find:: get rid of nested function (it's a gcc-ism)
[oweals/busybox.git] / miscutils / crontab.c
index 7d5709521ed94a5e29b663144b5443edc21dc3ea..4731d8da60aaa57b98a302bd58a73ccc4b86a012 100644 (file)
@@ -7,9 +7,19 @@
  * Copyright 1994 Matthew Dillon (dillon@apollo.west.oic.com)
  * Vladimir Oleynik <dzo@simtreas.ru> (C) 2002
  *
- * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
+//usage:#define crontab_trivial_usage
+//usage:       "[-c DIR] [-u USER] [-ler]|[FILE]"
+//usage:#define crontab_full_usage "\n\n"
+//usage:       "       -c      Crontab directory"
+//usage:     "\n       -u      User"
+//usage:     "\n       -l      List crontab"
+//usage:     "\n       -e      Edit crontab"
+//usage:     "\n       -r      Delete crontab"
+//usage:     "\n       FILE    Replace crontab by FILE ('-': stdin)"
+
 #include "libbb.h"
 
 #define CRONTABS        CONFIG_FEATURE_CROND_DIR "/crontabs"
 static void edit_file(const struct passwd *pas, const char *file)
 {
        const char *ptr;
-       int pid = vfork();
+       pid_t pid;
 
-       if (pid < 0) /* failure */
-               bb_perror_msg_and_die("vfork");
+       pid = xvfork();
        if (pid) { /* parent */
                wait4pid(pid);
                return;
@@ -32,8 +41,9 @@ static void edit_file(const struct passwd *pas, const char *file)
        /* CHILD - change user and run editor */
        /* initgroups, setgid, setuid */
        change_identity(pas);
-       setup_environment(DEFAULT_SHELL, 0,
-               SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, pas);
+       setup_environment(pas->pw_shell,
+                       SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP,
+                       pas);
        ptr = getenv("VISUAL");
        if (!ptr) {
                ptr = getenv("EDITOR");
@@ -42,7 +52,7 @@ static void edit_file(const struct passwd *pas, const char *file)
        }
 
        BB_EXECLP(ptr, ptr, file, NULL);
-       bb_perror_msg_and_die("exec %s", ptr);
+       bb_perror_msg_and_die("can't execute '%s'", ptr);
 }
 
 static int open_as_user(const struct passwd *pas, const char *file)
@@ -50,9 +60,7 @@ static int open_as_user(const struct passwd *pas, const char *file)
        pid_t pid;
        char c;
 
-       pid = vfork();
-       if (pid < 0) /* ERROR */
-               bb_perror_msg_and_die("vfork");
+       pid = xvfork();
        if (pid) { /* PARENT */
                if (wait4pid(pid) == 0) {
                        /* exitcode 0: child says it can read */