Skip to content

Commit d47dbfa

Browse files
author
syscl
committed
Added gCurTime(void); use calloc(args); credit @schdt899
1 parent 66ea363 commit d47dbfa

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

maclog.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//
2-
//
32
// maclog.h
43
// maclog
54
//
@@ -9,7 +8,7 @@
98
// This work is licensed under the Creative Commons Attribution-NonCommercial
109
// 4.0 Unported License => http://creativecommons.org/licenses/by-nc/4.0
1110
//
12-
#define PROGRAM_VER 1.1
11+
#define PROGRAM_VER 1.2
1312

1413
#include <Carbon/Carbon.h>
1514

@@ -18,6 +17,11 @@
1817
//
1918
#include <sys/stat.h>
2019
#include <fcntl.h>
20+
//
21+
// for time
22+
//
23+
#include <time.h>
24+
#include <string.h>
2125

2226
//
2327
// file permission, we use 0644 for both convince and safety reason
@@ -27,11 +31,12 @@
2731
//
2832
// get default log name and path
2933
//
30-
const char* gLogPath = "/tmp/system.log";
34+
char *gLogPath = "/tmp/system.log";
3135

3236
//
3337
// get log argv
3438
//
35-
char* gLogArgs[] = { "log", "show", "--predicate", "processID == 0", "--debug", 0 };
36-
char *gOpenf[3];
39+
//char* gLogArgs[] = { "log", "show", "--predicate", "processID == 0", "--debug", 0 };
40+
char* gLogArgs[] = { "log", "show", "--predicate", "process == \"kernel\" OR eventMessage CONTAINS \"kernel\"", "--style", "syslog", "--source", "--info", "--start", NULL, NULL };
41+
char* gOpenf[3];
3742

maclog.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
//
2020
#include "maclog.h"
2121

22+
char *gCurTime(void)
23+
{
24+
char *gTime = calloc(11, sizeof(char));
25+
time_t gRawTime = time(NULL);
26+
struct tm *gTimeInf = localtime(&gRawTime);
27+
sprintf(gTime, "%d-%d-%d",gTimeInf->tm_year + 1900, gTimeInf->tm_mon + 1, gTimeInf->tm_mday);
28+
return gTime;
29+
}
30+
2231
int main(int argc, char **argv)
2332
{
2433
pid_t rc;
@@ -33,6 +42,7 @@ int main(int argc, char **argv)
3342
close(STDOUT_FILENO);
3443
dup2(fd, STDOUT_FILENO);
3544
}
45+
gLogArgs[9] = gCurTime();
3646
//
3747
// log system log now
3848
//
@@ -45,8 +55,8 @@ int main(int argc, char **argv)
4555
//
4656
printf("v%.1f (c) 2017 syscl/lighting/Yating Zhou\n", PROGRAM_VER);
4757
wait(NULL);
48-
gOpenf[0] = strdup("open");
49-
gOpenf[1] = strdup(gLogPath);
58+
gOpenf[0] = "open";
59+
gOpenf[1] = gLogPath;
5060
gOpenf[2] = NULL;
5161
execvp(gOpenf[0], gOpenf);
5262
}

0 commit comments

Comments
 (0)