Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
exander77 committed Sep 5, 2023
1 parent 50b0ff3 commit 63fbcb0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions supertinycron.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ char* find_nth(const char* str, char ch, int n) {
return NULL;
}

void parse_line(char *line, TinyCronJob *job) {
job->schedule = line;
job->cmd = find_nth(line, ' ', line[0] == '@' ? 1 : 7);
if (!job->cmd) {
messageInt(1, "incomplete cron expression");
usage();
}
*job->cmd = '\0';
++job->cmd;
}
int main(int argc, char *argv[]) {
signal(SIGCHLD, sigchld_handler);
signal(SIGTERM, sig_handler);
Expand All @@ -129,7 +139,7 @@ int main(int argc, char *argv[]) {
usage();
}

if (argc <= 2) {
if (argc <= 1) {
messageInt(1, "incorrect number of arguments");
usage();
}
Expand Down Expand Up @@ -162,14 +172,7 @@ int main(int argc, char *argv[]) {
message(line, "line");
}

job.schedule = line;
job.cmd = find_nth(line, ' ', line[0] == '@' ? 1 : 7);
if (!job.cmd) {
messageInt(1, "incomplete cron expression");
usage();
}
*job.cmd = '\0';
++job.cmd;
parse_line(line, &job);

while (1) {
if (nap(&job)) {
Expand Down

0 comments on commit 63fbcb0

Please sign in to comment.