diff options
author | Rob Landley <rob@landley.net> | 2006-08-03 15:41:12 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-08-03 15:41:12 +0000 |
commit | d921b2ecc0d294ad4bf8c7458fc52a60c28727d2 (patch) | |
tree | e4a2769349867c441cf2983d83097bb66701a733 /miscutils/crontab.c | |
parent | 6dce0b6fa79f2d4bb7e9d90e1fbc0f6beb25f855 (diff) | |
download | busybox-w32-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.tar.gz busybox-w32-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.tar.bz2 busybox-w32-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.zip |
Remove bb_ prefixes from xfuncs.c (and a few other places), consolidate
things like xasprintf() into xfuncs.c, remove xprint_file_by_name() (it only
had one user), clean up lots of #includes... General cleanup pass. What I've
been doing for the last couple days.
And it conflicts! I've removed httpd.c from this checkin due to somebody else
touching that file. It builds for me. I have to catch a bus. (Now you know
why I'm looking forward to Mercurial.)
Diffstat (limited to 'miscutils/crontab.c')
-rw-r--r-- | miscutils/crontab.c | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 0ed59b0dc..a8e650c60 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -11,22 +11,6 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include "busybox.h" | 13 | #include "busybox.h" |
14 | #include <stdio.h> | ||
15 | #include <stdlib.h> | ||
16 | #include <stdarg.h> | ||
17 | #include <string.h> | ||
18 | #include <errno.h> | ||
19 | #include <time.h> | ||
20 | #include <dirent.h> | ||
21 | #include <fcntl.h> | ||
22 | #include <unistd.h> | ||
23 | #include <syslog.h> | ||
24 | #include <signal.h> | ||
25 | #include <getopt.h> | ||
26 | #include <sys/ioctl.h> | ||
27 | #include <sys/wait.h> | ||
28 | #include <sys/stat.h> | ||
29 | #include <sys/resource.h> | ||
30 | 14 | ||
31 | #ifndef CRONTABS | 15 | #ifndef CRONTABS |
32 | #define CRONTABS "/var/spool/cron/crontabs" | 16 | #define CRONTABS "/var/spool/cron/crontabs" |
@@ -47,8 +31,7 @@ static void EditFile(const char *user, const char *file); | |||
47 | static int GetReplaceStream(const char *user, const char *file); | 31 | static int GetReplaceStream(const char *user, const char *file); |
48 | static int ChangeUser(const char *user, short dochdir); | 32 | static int ChangeUser(const char *user, short dochdir); |
49 | 33 | ||
50 | int | 34 | int crontab_main(int ac, char **av) |
51 | crontab_main(int ac, char **av) | ||
52 | { | 35 | { |
53 | enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE; | 36 | enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE; |
54 | const struct passwd *pas; | 37 | const struct passwd *pas; |
@@ -147,7 +130,7 @@ crontab_main(int ac, char **av) | |||
147 | * Change directory to our crontab directory | 130 | * Change directory to our crontab directory |
148 | */ | 131 | */ |
149 | 132 | ||
150 | bb_xchdir(CDir); | 133 | xchdir(CDir); |
151 | 134 | ||
152 | /* | 135 | /* |
153 | * Handle options as appropriate | 136 | * Handle options as appropriate |
@@ -177,7 +160,7 @@ crontab_main(int ac, char **av) | |||
177 | char buf[1024]; | 160 | char buf[1024]; |
178 | 161 | ||
179 | snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid()); | 162 | snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid()); |
180 | fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); | 163 | fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); |
181 | chown(tmp, getuid(), getgid()); | 164 | chown(tmp, getuid(), getgid()); |
182 | if ((fi = fopen(pas->pw_name, "r"))) { | 165 | if ((fi = fopen(pas->pw_name, "r"))) { |
183 | while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) | 166 | while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) |
@@ -244,8 +227,7 @@ crontab_main(int ac, char **av) | |||
244 | return 0; | 227 | return 0; |
245 | } | 228 | } |
246 | 229 | ||
247 | static int | 230 | static int GetReplaceStream(const char *user, const char *file) |
248 | GetReplaceStream(const char *user, const char *file) | ||
249 | { | 231 | { |
250 | int filedes[2]; | 232 | int filedes[2]; |
251 | int pid; | 233 | int pid; |
@@ -284,7 +266,7 @@ GetReplaceStream(const char *user, const char *file) | |||
284 | exit(0); | 266 | exit(0); |
285 | 267 | ||
286 | bb_default_error_retval = 0; | 268 | bb_default_error_retval = 0; |
287 | fd = bb_xopen3(file, O_RDONLY, 0); | 269 | fd = xopen3(file, O_RDONLY, 0); |
288 | buf[0] = 0; | 270 | buf[0] = 0; |
289 | write(filedes[1], buf, 1); | 271 | write(filedes[1], buf, 1); |
290 | while ((n = read(fd, buf, sizeof(buf))) > 0) { | 272 | while ((n = read(fd, buf, sizeof(buf))) > 0) { |
@@ -293,8 +275,7 @@ GetReplaceStream(const char *user, const char *file) | |||
293 | exit(0); | 275 | exit(0); |
294 | } | 276 | } |
295 | 277 | ||
296 | static void | 278 | static void EditFile(const char *user, const char *file) |
297 | EditFile(const char *user, const char *file) | ||
298 | { | 279 | { |
299 | int pid; | 280 | int pid; |
300 | 281 | ||
@@ -324,8 +305,7 @@ EditFile(const char *user, const char *file) | |||
324 | wait4(pid, NULL, 0, NULL); | 305 | wait4(pid, NULL, 0, NULL); |
325 | } | 306 | } |
326 | 307 | ||
327 | static int | 308 | static int ChangeUser(const char *user, short dochdir) |
328 | ChangeUser(const char *user, short dochdir) | ||
329 | { | 309 | { |
330 | struct passwd *pas; | 310 | struct passwd *pas; |
331 | 311 | ||
@@ -349,7 +329,7 @@ ChangeUser(const char *user, short dochdir) | |||
349 | if (dochdir) { | 329 | if (dochdir) { |
350 | if (chdir(pas->pw_dir) < 0) { | 330 | if (chdir(pas->pw_dir) < 0) { |
351 | bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir); | 331 | bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir); |
352 | bb_xchdir(TMPDIR); | 332 | xchdir(TMPDIR); |
353 | } | 333 | } |
354 | } | 334 | } |
355 | return(pas->pw_uid); | 335 | return(pas->pw_uid); |