|
5 | 5 | */
|
6 | 6 | #include "cron_support.h"
|
7 | 7 |
|
8 | | -extern char reservation_command[BUFFER_SIZE][MAX_BUFFER_SIZE]; |
| 8 | +FILE *fp; |
| 9 | +pthread_attr_t mutex; // 뮤텍스 객체 선언 |
| 10 | +extern char reservation_command[BUFFER_SIZE][MAX_BUFFER_SIZE]; // 예약 명령 목록 |
9 | 11 |
|
10 | 12 | /**
|
11 | 13 | * @brief 입력한 명령행을 토큰 구조체로 변환
|
@@ -84,39 +86,39 @@ int get_reservation_command(void) // 예약 명령 목록 가져오
|
84 | 86 | */
|
85 | 87 | void write_log(int command_type, char *command) // 로그 파일에 이력 기록
|
86 | 88 | {
|
87 | | - //FILE *fp; |
88 | 89 | time_t now_t;
|
89 | 90 | struct tm *now_tm;
|
90 | 91 | char temp[MAX_BUFFER_SIZE];
|
91 | 92 |
|
92 | | - /* |
| 93 | + pthread_mutex_lock(&mutex); |
93 | 94 | if ((fp = fopen(CRONTAB_LOG, "r+")) == NULL)
|
94 | 95 | {
|
95 | 96 | fprintf(stderr, "write_log: fopen error for %s\n", CRONTAB_LOG);
|
96 | 97 | return;
|
97 | 98 | }
|
98 | 99 | fseek(fp, 0, SEEK_END);
|
99 | | -*/ |
| 100 | + |
100 | 101 | time(&now_t);
|
101 | 102 | now_tm = localtime(&now_t);
|
102 | 103 |
|
103 | 104 | switch (command_type) {
|
104 | 105 | case ADD:
|
105 | | - sprintf(temp, "echo \"[%.24s] %s %s\" >> %s", asctime(now_tm), "add", command, CRONTAB_LOG); |
106 | | - //fprintf(fp, "[%.24s] %s %s\n", asctime(now_tm), "add", command); |
| 106 | + //sprintf(temp, "echo \"[%.24s] %s %s\" >> %s", asctime(now_tm), "add", command, CRONTAB_LOG); |
| 107 | + fprintf(fp, "[%.24s] %s %s\n", asctime(now_tm), "add", command); |
107 | 108 | break;
|
108 | 109 | case REMOVE:
|
109 | | - sprintf(temp, "echo \"[%.24s] %s %s\" >> %s", asctime(now_tm), "remove", command, CRONTAB_LOG); |
110 | | - //fprintf(fp, "[%.24s] %s %s\n", asctime(now_tm), "remove", command); |
| 110 | + //sprintf(temp, "echo \"[%.24s] %s %s\" >> %s", asctime(now_tm), "remove", command, CRONTAB_LOG); |
| 111 | + fprintf(fp, "[%.24s] %s %s\n", asctime(now_tm), "remove", command); |
111 | 112 | break;
|
112 | 113 | case RUN:
|
113 | | - sprintf(temp, "echo \"[%.24s] %s %s\" >> %s", asctime(now_tm), "run", command, CRONTAB_LOG); |
114 | | - //fprintf(fp, "[%.24s] %s %s\n", asctime(now_tm), "run", command); |
| 114 | + //sprintf(temp, "echo \"[%.24s] %s %s\" >> %s", asctime(now_tm), "run", command, CRONTAB_LOG); |
| 115 | + fprintf(fp, "[%.24s] %s %s\n", asctime(now_tm), "run", command); |
115 | 116 | break;
|
116 | 117 | }
|
117 | | - system(temp); |
| 118 | + //system(temp); |
118 | 119 | //fflush(fp);
|
119 | | - //fclose(fp); |
| 120 | + fclose(fp); |
| 121 | + pthread_mutex_unlock(&mutex); |
120 | 122 | }
|
121 | 123 |
|
122 | 124 |
|
0 commit comments