crontab: we indent using tabs

This commit is contained in:
Denis Vlasenko 2006-09-27 19:48:56 +00:00
parent 956a569360
commit 94d5d82bd8

View File

@ -39,10 +39,12 @@ int crontab_main(int ac, char **av)
int repFd = 0; int repFd = 0;
int i; int i;
char caller[256]; /* user that ran program */ char caller[256]; /* user that ran program */
char buf[1024];
int UserId; int UserId;
UserId = getuid(); UserId = getuid();
if ((pas = getpwuid(UserId)) == NULL) pas = getpwuid(UserId);
if (pas == NULL)
bb_perror_msg_and_die("getpwuid"); bb_perror_msg_and_die("getpwuid");
safe_strncpy(caller, pas->pw_name, sizeof(caller)); safe_strncpy(caller, pas->pw_name, sizeof(caller));
@ -113,7 +115,8 @@ int crontab_main(int ac, char **av)
* Get password entry * Get password entry
*/ */
if ((pas = getpwuid(UserId)) == NULL) pas = getpwuid(UserId);
if (pas == NULL)
bb_perror_msg_and_die("getpwuid"); bb_perror_msg_and_die("getpwuid");
/* /*
@ -140,9 +143,9 @@ int crontab_main(int ac, char **av)
case LIST: case LIST:
{ {
FILE *fi; FILE *fi;
char buf[1024];
if ((fi = fopen(pas->pw_name, "r"))) { fi = fopen(pas->pw_name, "r");
if (fi) {
while (fgets(buf, sizeof(buf), fi) != NULL) while (fgets(buf, sizeof(buf), fi) != NULL)
fputs(buf, stdout); fputs(buf, stdout);
fclose(fi); fclose(fi);
@ -157,12 +160,12 @@ int crontab_main(int ac, char **av)
int fd; int fd;
int n; int n;
char tmp[128]; char tmp[128];
char buf[1024];
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid()); snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
chown(tmp, getuid(), getgid()); chown(tmp, getuid(), getgid());
if ((fi = fopen(pas->pw_name, "r"))) { fi = fopen(pas->pw_name, "r");
if (fi) {
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
write(fd, buf, n); write(fd, buf, n);
} }
@ -175,13 +178,13 @@ int crontab_main(int ac, char **av)
/* fall through */ /* fall through */
case REPLACE: case REPLACE:
{ {
char buf[1024];
char path[1024]; char path[1024];
int fd; int fd;
int n; int n;
snprintf(path, sizeof(path), "%s.new", pas->pw_name); snprintf(path, sizeof(path), "%s.new", pas->pw_name);
if ((fd = open(path, O_CREAT|O_TRUNC|O_APPEND|O_WRONLY, 0600)) >= 0) { fd = open(path, O_CREAT|O_TRUNC|O_APPEND|O_WRONLY, 0600);
if (fd >= 0) {
while ((n = read(repFd, buf, sizeof(buf))) > 0) { while ((n = read(repFd, buf, sizeof(buf))) > 0) {
write(fd, buf, n); write(fd, buf, n);
} }
@ -237,11 +240,12 @@ static int GetReplaceStream(const char *user, const char *file)
if (pipe(filedes) < 0) { if (pipe(filedes) < 0) {
perror("pipe"); perror("pipe");
return(-1); return -1;
} }
if ((pid = fork()) < 0) { pid = fork();
if (pid < 0) {
perror("fork"); perror("fork");
return(-1); return -1;
} }
if (pid > 0) { if (pid > 0) {
/* /*
@ -253,7 +257,7 @@ static int GetReplaceStream(const char *user, const char *file)
close(filedes[0]); close(filedes[0]);
filedes[0] = -1; filedes[0] = -1;
} }
return(filedes[0]); return filedes[0];
} }
/* /*
@ -277,9 +281,9 @@ static int GetReplaceStream(const char *user, const char *file)
static void EditFile(const char *user, const char *file) static void EditFile(const char *user, const char *file)
{ {
int pid; int pid = fork();
if ((pid = fork()) == 0) { if (pid == 0) {
/* /*
* CHILD - change user and run editor * CHILD - change user and run editor
*/ */
@ -288,7 +292,8 @@ static void EditFile(const char *user, const char *file)
if (ChangeUser(user, 1) < 0) if (ChangeUser(user, 1) < 0)
exit(0); exit(0);
if ((ptr = getenv("VISUAL")) == NULL || strlen(ptr) > 256) ptr = getenv("VISUAL");
if (ptr == NULL || strlen(ptr) > 256)
ptr = PATH_VI; ptr = PATH_VI;
snprintf(visual, sizeof(visual), "%s %s", ptr, file); snprintf(visual, sizeof(visual), "%s %s", ptr, file);
@ -313,9 +318,9 @@ static int ChangeUser(const char *user, short dochdir)
* Obtain password entry and change privileges * Obtain password entry and change privileges
*/ */
if ((pas = getpwnam(user)) == NULL) { pas = getpwnam(user);
if (pas == NULL) {
bb_perror_msg_and_die("failed to get uid for %s", user); bb_perror_msg_and_die("failed to get uid for %s", user);
return(-1);
} }
setenv("USER", pas->pw_name, 1); setenv("USER", pas->pw_name, 1);
setenv("HOME", pas->pw_dir, 1); setenv("HOME", pas->pw_dir, 1);
@ -328,9 +333,9 @@ static int ChangeUser(const char *user, short dochdir)
if (dochdir) { if (dochdir) {
if (chdir(pas->pw_dir) < 0) { if (chdir(pas->pw_dir) < 0) {
bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir); bb_perror_msg("chdir(%s) by %s failed", pas->pw_dir, user);
xchdir(TMPDIR); xchdir(TMPDIR);
} }
} }
return(pas->pw_uid); return pas->pw_uid;
} }