Changeset 783

Show
Ignore:
Timestamp:
06/12/08 03:36:09 (3 months ago)
Author:
dormando
Message:

make -k work under daemon mode (-d).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/server/ChangeLog

    r741 r783  
     12008-06-11 
     2 
     3       * Fix -k to work with -d. (reported by Gary Zhu) 
     4 
    152008-03-02 [Version 1.2.5-rc1 released] 
    26 
  • trunk/server/memcached.c

    r736 r783  
    30053005    } 
    30063006 
    3007     /* lock paged memory if needed */ 
    3008     if (lock_memory) { 
    3009 #ifdef HAVE_MLOCKALL 
    3010         int res = mlockall(MCL_CURRENT | MCL_FUTURE); 
    3011         if (res != 0) { 
    3012             fprintf(stderr, "warning: -k invalid, mlockall() failed: %s\n", 
    3013                     strerror(errno)); 
    3014         } 
    3015 #else 
    3016         fprintf(stderr, "warning: -k invalid, mlockall() not supported on this platform.  proceeding without.\n"); 
    3017 #endif 
    3018     } 
    3019  
    3020     /* lose root privileges if we have them */ 
    3021     if (getuid() == 0 || geteuid() == 0) { 
    3022         if (username == 0 || *username == '\0') { 
    3023             fprintf(stderr, "can't run as root without the -u switch\n"); 
    3024             return 1; 
    3025         } 
    3026         if ((pw = getpwnam(username)) == 0) { 
    3027             fprintf(stderr, "can't find the user %s to switch to\n", username); 
    3028             return 1; 
    3029         } 
    3030         if (setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) { 
    3031             fprintf(stderr, "failed to assume identity of user %s\n", username); 
    3032             return 1; 
    3033         } 
    3034     } 
    3035  
    30363007    /* daemonize if requested */ 
    30373008    /* if we want to ensure our ability to dump core, don't chdir to / */ 
     
    30453016    } 
    30463017 
     3018    /* lock paged memory if needed */ 
     3019    if (lock_memory) { 
     3020#ifdef HAVE_MLOCKALL 
     3021        int res = mlockall(MCL_CURRENT | MCL_FUTURE); 
     3022        if (res != 0) { 
     3023            fprintf(stderr, "warning: -k invalid, mlockall() failed: %s\n", 
     3024                    strerror(errno)); 
     3025        } 
     3026#else 
     3027        fprintf(stderr, "warning: -k invalid, mlockall() not supported on this platform.  proceeding without.\n"); 
     3028#endif 
     3029    } 
     3030 
     3031    /* lose root privileges if we have them */ 
     3032    if (getuid() == 0 || geteuid() == 0) { 
     3033        if (username == 0 || *username == '\0') { 
     3034            fprintf(stderr, "can't run as root without the -u switch\n"); 
     3035            return 1; 
     3036        } 
     3037        if ((pw = getpwnam(username)) == 0) { 
     3038            fprintf(stderr, "can't find the user %s to switch to\n", username); 
     3039            return 1; 
     3040        } 
     3041        if (setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) { 
     3042            fprintf(stderr, "failed to assume identity of user %s\n", username); 
     3043            return 1; 
     3044        } 
     3045    } 
    30473046 
    30483047    /* initialize main thread libevent instance */