|
Lines 81-86
Link Here
|
| 81 |
struct conf_entry *next;/* Linked list pointer */ |
81 |
struct conf_entry *next;/* Linked list pointer */ |
| 82 |
}; |
82 |
}; |
| 83 |
|
83 |
|
|
|
84 |
struct log_entry { |
| 85 |
char *log; /* name of the log to be compressed */ |
| 86 |
struct log_entry* next; /* Linked list pointer */ |
| 87 |
}; |
| 88 |
|
| 89 |
struct kill_entry { |
| 90 |
pid_t pid; /* PID to kill */ |
| 91 |
int sig; /* Signal to send */ |
| 92 |
struct kill_entry* next;/* Linked list pointer */ |
| 93 |
}; |
| 94 |
|
| 95 |
struct kill_entry* kill_pending = NULL; |
| 96 |
/* List of PIDs to be killed */ |
| 97 |
struct log_entry* log_pending = NULL; |
| 98 |
/* List of logs to be compressed */ |
| 99 |
|
| 84 |
int archtodir = 0; /* Archive old logfiles to other directory */ |
100 |
int archtodir = 0; /* Archive old logfiles to other directory */ |
| 85 |
int verbose = 0; /* Print out what's going on */ |
101 |
int verbose = 0; /* Print out what's going on */ |
| 86 |
int needroot = 1; /* Root privs are necessary */ |
102 |
int needroot = 1; /* Root privs are necessary */ |
|
Lines 99-104
Link Here
|
| 99 |
static char *sob(char *p); |
115 |
static char *sob(char *p); |
| 100 |
static char *son(char *p); |
116 |
static char *son(char *p); |
| 101 |
static char *missing_field(char *p, char *errline); |
117 |
static char *missing_field(char *p, char *errline); |
|
|
118 |
static int save_kill(pid_t pid, int sig); |
| 119 |
static void save_compress_log(char* file); |
| 102 |
static void do_entry(struct conf_entry * ent); |
120 |
static void do_entry(struct conf_entry * ent); |
| 103 |
static void PRS(int argc, char **argv); |
121 |
static void PRS(int argc, char **argv); |
| 104 |
static void usage(); |
122 |
static void usage(); |
|
Lines 117-122
Link Here
|
| 117 |
main(int argc, char **argv) |
135 |
main(int argc, char **argv) |
| 118 |
{ |
136 |
{ |
| 119 |
struct conf_entry *p, *q; |
137 |
struct conf_entry *p, *q; |
|
|
138 |
struct kill_entry* k; |
| 139 |
struct log_entry* l; |
| 140 |
int notified; |
| 120 |
|
141 |
|
| 121 |
PRS(argc, argv); |
142 |
PRS(argc, argv); |
| 122 |
if (needroot && getuid() && geteuid()) |
143 |
if (needroot && getuid() && geteuid()) |
|
Lines 129-134
Link Here
|
| 129 |
free((char *) q); |
150 |
free((char *) q); |
| 130 |
q = p; |
151 |
q = p; |
| 131 |
} |
152 |
} |
|
|
153 |
|
| 154 |
notified = 0; |
| 155 |
while (kill_pending) { |
| 156 |
if (kill(kill_pending->pid, kill_pending->sig)) |
| 157 |
warn("can't notify daemon, pid %d", (int) kill_pending->pid); |
| 158 |
else { |
| 159 |
notified = 1; |
| 160 |
if (verbose) |
| 161 |
printf("daemon pid %d notified\n", (int) kill_pending->pid); |
| 162 |
} |
| 163 |
k = kill_pending; |
| 164 |
kill_pending = kill_pending->next; |
| 165 |
free((char *) k); |
| 166 |
} |
| 167 |
if (notified) { |
| 168 |
if (verbose) |
| 169 |
printf("small pause to allow daemons to close logs\n"); |
| 170 |
sleep(10); |
| 171 |
} |
| 172 |
|
| 173 |
while (log_pending) { |
| 174 |
compress_log(log_pending->log); |
| 175 |
free(log_pending->log); |
| 176 |
l = log_pending; |
| 177 |
log_pending = log_pending->next; |
| 178 |
free((char *) l); |
| 179 |
} |
| 180 |
|
| 132 |
return (0); |
181 |
return (0); |
| 133 |
} |
182 |
} |
| 134 |
|
183 |
|
|
Lines 470-475
Link Here
|
| 470 |
return (p); |
519 |
return (p); |
| 471 |
} |
520 |
} |
| 472 |
|
521 |
|
|
|
522 |
static int |
| 523 |
save_kill(pid_t pid, int sig) |
| 524 |
{ |
| 525 |
struct kill_entry* p; |
| 526 |
|
| 527 |
for (p = kill_pending; p != NULL; p = p->next) |
| 528 |
if (p->pid == pid && p->sig == sig) |
| 529 |
return (0); |
| 530 |
|
| 531 |
p = (struct kill_entry *) malloc(sizeof(struct kill_entry)); |
| 532 |
p->pid = pid; |
| 533 |
p->sig = sig; |
| 534 |
p->next = kill_pending; |
| 535 |
kill_pending = p; |
| 536 |
return (0); |
| 537 |
} |
| 538 |
|
| 539 |
static void |
| 540 |
save_compress_log(char *file) |
| 541 |
{ |
| 542 |
struct log_entry* p; |
| 543 |
|
| 544 |
for (p = log_pending; p != NULL; p = p->next) |
| 545 |
if (!strcmp(p->log, file)) |
| 546 |
return; |
| 547 |
|
| 548 |
p = (struct log_entry *) malloc(sizeof(struct log_entry)); |
| 549 |
p->log = strdup(file); |
| 550 |
p->next = log_pending; |
| 551 |
log_pending = p; |
| 552 |
} |
| 553 |
|
| 473 |
static void |
554 |
static void |
| 474 |
dotrim(char *log, char *pid_file, int numdays, int flags, int perm, |
555 |
dotrim(char *log, char *pid_file, int numdays, int flags, int perm, |
| 475 |
int owner_uid, int group_gid, int sig) |
556 |
int owner_uid, int group_gid, int sig) |
|
Lines 613-624
Link Here
|
| 613 |
if (noaction) { |
694 |
if (noaction) { |
| 614 |
notified = 1; |
695 |
notified = 1; |
| 615 |
printf("kill -%d %d\n", sig, (int) pid); |
696 |
printf("kill -%d %d\n", sig, (int) pid); |
| 616 |
} else if (kill(pid, sig)) |
697 |
} else if (save_kill(pid, sig)) |
| 617 |
warn("can't notify daemon, pid %d", (int) pid); |
698 |
warn("can't notify daemon, pid %d", (int) pid); |
| 618 |
else { |
699 |
else { |
| 619 |
notified = 1; |
700 |
notified = 1; |
| 620 |
if (verbose) |
701 |
if (verbose) |
| 621 |
printf("daemon pid %d notified\n", (int) pid); |
702 |
printf("will notify daemon pid %d\n", (int) pid); |
| 622 |
} |
703 |
} |
| 623 |
} |
704 |
} |
| 624 |
if ((flags & CE_COMPACT)) { |
705 |
if ((flags & CE_COMPACT)) { |
|
Lines 627-642
Link Here
|
| 627 |
else if (noaction) |
708 |
else if (noaction) |
| 628 |
printf("Compress %s.0\n", log); |
709 |
printf("Compress %s.0\n", log); |
| 629 |
else { |
710 |
else { |
| 630 |
if (notified) { |
|
|
| 631 |
if (verbose) |
| 632 |
printf("small pause to allow daemon to close log\n"); |
| 633 |
sleep(10); |
| 634 |
} |
| 635 |
if (archtodir) { |
711 |
if (archtodir) { |
| 636 |
(void) sprintf(file1, "%s/%s", dirpart, namepart); |
712 |
(void) sprintf(file1, "%s/%s", dirpart, namepart); |
| 637 |
compress_log(file1); |
713 |
(pid == 0 ? compress_log : save_compress_log)(file1); |
| 638 |
} else { |
714 |
} else { |
| 639 |
compress_log(log); |
715 |
(pid == 0 ? compress_log : save_compress_log)(log); |
| 640 |
} |
716 |
} |
| 641 |
} |
717 |
} |
| 642 |
} |
718 |
} |