Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 30DFCE94E for ; Tue, 20 Nov 2012 12:41:34 +0000 (UTC) Received: (qmail 26271 invoked by uid 500); 20 Nov 2012 12:41:33 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 26062 invoked by uid 500); 20 Nov 2012 12:41:30 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 26001 invoked by uid 99); 20 Nov 2012 12:41:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Nov 2012 12:41:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Nov 2012 12:41:26 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9DD2A238896F for ; Tue, 20 Nov 2012 12:41:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1411644 - /commons/proper/daemon/branches/1.0.x/src/native/unix/native/jsvc-unix.c Date: Tue, 20 Nov 2012 12:41:05 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121120124105.9DD2A238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Tue Nov 20 12:41:04 2012 New Revision: 1411644 URL: http://svn.apache.org/viewvc?rev=1411644&view=rev Log: Implement correct directory from file-path funtion Modified: commons/proper/daemon/branches/1.0.x/src/native/unix/native/jsvc-unix.c Modified: commons/proper/daemon/branches/1.0.x/src/native/unix/native/jsvc-unix.c URL: http://svn.apache.org/viewvc/commons/proper/daemon/branches/1.0.x/src/native/unix/native/jsvc-unix.c?rev=1411644&r1=1411643&r2=1411644&view=diff ============================================================================== --- commons/proper/daemon/branches/1.0.x/src/native/unix/native/jsvc-unix.c (original) +++ commons/proper/daemon/branches/1.0.x/src/native/unix/native/jsvc-unix.c Tue Nov 20 12:41:04 2012 @@ -498,10 +498,6 @@ static sighandler_t signal_set(int sig, return hand; } -/* - * Check pid and if still running - */ - static int mkdir0(const char *name, int perms) { if (mkdir(name, perms) == 0) @@ -510,7 +506,7 @@ static int mkdir0(const char *name, int return errno; } -static int mkdir1(const char *name, int perms) +static int mkdir1(char *name, int perms) { int rc; @@ -519,24 +515,43 @@ static int mkdir1(const char *name, int return 0; if (rc == ENOENT) { /* Missing an intermediate dir */ char *pos; - char *dir = strdup(name); - if (!dir) - return ENOMEM; - if ((pos = strrchr(dir, '/'))) { + if ((pos = strrchr(name, '/'))) { *pos = '\0'; - if (*dir) { - if (!(rc = mkdir1(dir, perms))) { + if (*name) { + if (!(rc = mkdir1(name, perms))) { /* Try again, now with parents created */ + *pos = '/'; rc = mkdir0(name, perms); } } + *pos = '/'; } - free(dir); } return rc; } +static int mkdir2(const char *name, int perms) +{ + int rc = 0; + char *pos; + char *dir = strdup(name); + + if (!dir) + return ENOMEM; + if ((pos = strrchr(dir, '/'))) { + *pos = '\0'; + if (*dir) + rc = mkdir1(dir, perms); + } + free(dir); + return rc; +} + +/* + * Check pid and if still running + */ + static int check_pid(arg_data *args) { int fd; @@ -551,7 +566,7 @@ retry: if (fd < 0) { if (once == 0 && (errno == ENOTDIR || errno == ENOENT)) { once = 1; - if (mkdir1(args->pidf, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH) == 0) + if (mkdir2(args->pidf, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH) == 0) goto retry; } log_error("Cannot open PID file %s, PID is %d", args->pidf, pidn);