Show
Ignore:
Timestamp:
10/16/07 01:13:43 (2 years ago)
Author:
plindner
Message:

Patch from David Bremner <bremner@…> that implements a new option "-a"
which takes an octal permission mask (like chmod) sets the permissions
on the unix domain socket (specified by "-s").

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/server/memcached.c

    r627 r629  
    165165 
    166166static void settings_init(void) { 
     167    settings.access=0700; 
    167168    settings.port = 11211; 
    168169    settings.udpport = 0; 
     
    761762                memcpy(ITEM_data(new_it) + old_it->nbytes - 2 /* CRLF */, ITEM_data(it), it->nbytes); 
    762763            } else { 
    763                 /* NREAD_PREPEND */  
     764                /* NREAD_PREPEND */ 
    764765                memcpy(ITEM_data(new_it), ITEM_data(it), it->nbytes); 
    765766                memcpy(ITEM_data(new_it) + it->nbytes - 2 /* CRLF */, ITEM_data(old_it), old_it->nbytes); 
     
    22792280} 
    22802281 
    2281 static int server_socket_unix(const char *path) { 
     2282static int server_socket_unix(const char *path, int access_mask) { 
    22822283    int sfd; 
    22832284    struct linger ling = {0, 0}; 
     
    22852286    struct stat tstat; 
    22862287    int flags =1; 
     2288    int old_umask; 
    22872289 
    22882290    if (!path) { 
     
    23142316    addr.sun_family = AF_UNIX; 
    23152317    strcpy(addr.sun_path, path); 
     2318    old_umask=umask( ~(access_mask&0777)); 
    23162319    if (bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { 
    23172320        perror("bind()"); 
    23182321        close(sfd); 
     2322        umask(old_umask); 
    23192323        return -1; 
    23202324    } 
     2325    umask(old_umask); 
    23212326    if (listen(sfd, 1024) == -1) { 
    23222327        perror("listen()"); 
     
    25682573 
    25692574    /* process arguments */ 
    2570     while ((c = getopt(argc, argv, "bp:s:U:m:Mc:khirvdl:u:P:f:s:n:t:D:")) != -1) { 
     2575    while ((c = getopt(argc, argv, "a:bp:s:U:m:Mc:khirvdl:u:P:f:s:n:t:D:")) != -1) { 
    25712576        switch (c) { 
     2577        case 'a': 
     2578            /* access for unix domain socket, as octal mask (like chmod)*/ 
     2579            settings.access= strtol(optarg,NULL,8); 
     2580            break; 
     2581 
    25722582        case 'U': 
    25732583            settings.udpport = atoi(optarg); 
     
    27472757    /* create unix mode sockets after dropping privileges */ 
    27482758    if (settings.socketpath != NULL) { 
    2749         l_socket = server_socket_unix(settings.socketpath); 
     2759        l_socket = server_socket_unix(settings.socketpath,settings.access); 
    27502760        if (l_socket == -1) { 
    27512761            fprintf(stderr, "failed to listen\n");