]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added a bit more generic get_process_capability() function.
authorTimo Sirainen <tss@iki.fi>
Sat, 27 Dec 2008 07:19:04 +0000 (09:19 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 27 Dec 2008 07:19:04 +0000 (09:19 +0200)
To make life easier for managesieve patch. Patch by Stephan Bosch.

--HG--
branch : HEAD

src/master/master-settings.c

index 93bbdf50164b587dbd99954d92ce984e6acf6db4..4b258e65053c9e4a750c0582512f960d1cd95d26 100644 (file)
@@ -655,17 +655,18 @@ static void unlink_auth_sockets(const char *path, const char *prefix)
 }
 
 #ifdef HAVE_MODULES
-static bool get_imap_capability(struct settings *set)
+static const char *
+get_process_capability(enum process_type ptype, struct settings *set)
 {
        /* FIXME: pretty ugly code just for getting the capability
           automatically */
-       static const char *generated_capability = NULL;
        static const char *args[] = {
                "uid=65534",
                "gid=65534",
                "home=/tmp",
                NULL
        };
+       const char *pname = process_names[ptype];
        enum master_login_status login_status;
        struct mail_login_request request;
        char buf[4096];
@@ -675,16 +676,6 @@ static bool get_imap_capability(struct settings *set)
        uid_t uid;
        pid_t pid;
 
-       if (generated_capability != NULL) {
-               /* Reloading configuration. Don't try to execute the imap
-                  process again. Too risky and the wait() call below will
-                  break it anyway. Just use the previous capability list we
-                  already had generated. */
-               set->imap_generated_capability =
-                       p_strdup(settings_pool, generated_capability);
-               return TRUE;
-       }
-
        uid = geteuid();
        if (uid != 0) {
                /* use the current user */
@@ -694,39 +685,42 @@ static bool get_imap_capability(struct settings *set)
 
        if (pipe(fd) < 0) {
                i_error("pipe() failed: %m");
-               return FALSE;
+               return NULL;
        }
        fd_close_on_exec(fd[0], TRUE);
        fd_close_on_exec(fd[1], TRUE);
 
        memset(&request, 0, sizeof(request));
        request.fd = fd[1];
-       login_status = create_mail_process(PROCESS_TYPE_IMAP, set, &request,
+       login_status = create_mail_process(ptype, set, &request,
                                           "dump-capability", args, NULL, TRUE,
                                           &pid);
        if (login_status != MASTER_LOGIN_STATUS_OK) {
                (void)close(fd[0]);
                (void)close(fd[1]);
-               return FALSE;
+               return NULL;
        }
        (void)close(fd[1]);
 
        alarm(5);
-       if (wait(&status) == -1)
-               i_fatal("imap dump-capability process %d got stuck", (int)pid);
+       if (wait(&status) == -1) {
+               i_fatal("%s dump-capability process %d got stuck",
+                       pname, (int)pid);
+       }
        alarm(0);
 
        if (status != 0) {
                (void)close(fd[0]);
                if (WIFSIGNALED(status)) {
-                       i_error("imap dump-capability process "
-                               "killed with signal %d", WTERMSIG(status));
+                       i_error("%s dump-capability process "
+                               "killed with signal %d",
+                               pname, WTERMSIG(status));
                } else {
-                       i_error("imap dump-capability process returned %d",
-                               WIFEXITED(status) ? WEXITSTATUS(status) :
+                       i_error("%s dump-capability process returned %d",
+                               pname, WIFEXITED(status) ? WEXITSTATUS(status) :
                                status);
                }
-               return FALSE;
+               return NULL;
        }
 
        pos = 0;
@@ -734,20 +728,40 @@ static bool get_imap_capability(struct settings *set)
                pos += ret;
 
        if (ret < 0) {
-               i_error("read(imap dump-capability process) failed: %m");
+               i_error("read(%s dump-capability process) failed: %m", pname);
                (void)close(fd[0]);
-               return FALSE;
+               return NULL;
        }
        (void)close(fd[0]);
 
        if (pos == 0 || buf[pos-1] != '\n') {
-               i_error("imap dump-capability: Couldn't read capability "
-                       "(got %u bytes)", pos);
-               return FALSE;
+               i_error("%s dump-capability: Couldn't read capability "
+                       "(got %u bytes)", pname, pos);
+               return NULL;
        }
        buf[pos-1] = '\0';
 
-       generated_capability = i_strdup(buf);
+       return i_strdup(buf);
+}
+
+static bool get_imap_capability(struct settings *set)
+{
+       static const char *generated_capability = NULL;
+
+       if (generated_capability != NULL) {
+               /* Reloading configuration. Don't try to execute the imap
+                  process again. Too risky and the wait() call below will
+                  break it anyway. Just use the previous capability list we
+                  already had generated. */
+               set->imap_generated_capability =
+                       p_strdup(settings_pool, generated_capability);
+               return TRUE;
+       }
+
+       generated_capability = get_process_capability(PROCESS_TYPE_IMAP, set);
+       if (generated_capability == NULL)
+               return FALSE;
+
        set->imap_generated_capability =
                p_strdup(settings_pool, generated_capability);
        return TRUE;