Changeset 2526

Show
Ignore:
Timestamp:
09/25/07 20:04:09 (10 months ago)
Author:
dfriedrich
Message:

closed SIGHUP bug again ;-) (FD_CLOEXEC needs to be set)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/opensync/client/opensync_client.c

    r2368 r2526  
    10591059        OSyncError *error = NULL; 
    10601060 
    1061         osync_trace(TRACE_INTERNAL, "plugin received command %i", osync_message_get_command(message)); 
     1061        osync_trace(TRACE_INTERNAL, "plugin received command %i (%s)", osync_message_get_command(message), osync_message_get_commandstr(message)); 
    10621062 
    10631063        switch (osync_message_get_command(message)) { 
     
    12631263                        osync_queue_free(client->outgoing); 
    12641264                } 
    1265          
     1265                
    12661266                if (client->plugin) 
    12671267                        osync_plugin_unref(client->plugin); 
  • trunk/opensync/client/opensync_client_proxy.c

    r2525 r2526  
    4040#ifdef _WIN32 
    4141/* Historical signals specified by POSIX. */ 
    42 #define SIGKILL 9       /* Kill (cannot be blocked, caught, or ignored).  */ 
     42#define SIGKILL 9   /* Kill (cannot be blocked, caught, or ignored).  */ 
    4343#define SIGTERM 15      /* can be caught and interpreted or ignored by the process */ 
    4444#endif //_WIN32 
     
    7979 
    8080//portable kill pid helper 
    81 #if 0 
    82 static int _osync_kill(pid_t pid, int sig)  
     81/*static int _osync_kill(pid_t pid, int sig)  
    8382{ 
    8483#ifndef _WIN32 
     
    107106        return (ret); 
    108107#endif //_WIN32 
    109 }  
    110 #endif 
    111  
    112 #if 0 
    113 static char *_osync_client_pid_filename(OSyncClientProxy *proxy) 
     108}*/ 
     109 
     110/*static char *_osync_client_pid_filename(OSyncClientProxy *proxy) 
    114111{ 
    115112        return g_strdup_printf("%s/osplugin.pid", proxy->path); 
    116 } 
    117  
    118 static osync_bool osync_client_remove_pidfile(OSyncClientProxy *proxy, OSyncError **error) 
     113}*/ 
     114 
     115/*static osync_bool osync_client_remove_pidfile(OSyncClientProxy *proxy, OSyncError **error) 
    119116{ 
    120117        char *pidpath = _osync_client_pid_filename(proxy); 
     
    128125        g_free(pidpath); 
    129126        return TRUE; 
    130 } 
    131  
    132 static osync_bool _osync_client_create_pidfile(OSyncClientProxy *proxy, OSyncError **error) 
     127}*/ 
     128 
     129/*static osync_bool _osync_client_create_pidfile(OSyncClientProxy *proxy, OSyncError **error) 
    133130{ 
    134131        char *pidpath = _osync_client_pid_filename(proxy); 
     
    144141        g_free(pidpath); 
    145142        return TRUE; 
    146 } 
    147  
    148 static osync_bool _osync_client_kill_old_osplugin(OSyncClientProxy *proxy, OSyncError **error) 
     143}*/ 
     144 
     145/*static osync_bool _osync_client_kill_old_osplugin(OSyncClientProxy *proxy, OSyncError **error) 
    149146{ 
    150147        osync_bool ret = FALSE; 
     
    156153        char *pidpath = _osync_client_pid_filename(proxy); 
    157154 
    158         /* Simply returns if there is no PID file */ 
     155        // Simply returns if there is no PID file 
    159156        if (!g_file_test(pidpath, G_FILE_TEST_EXISTS)) { 
    160157                ret = TRUE; 
     
    173170        if (_osync_kill(pid, SIGTERM) < 0) { 
    174171                osync_trace(TRACE_INTERNAL, "Error killing old osplugin: %s. Stale pid file?", g_strerror(errno)); 
    175                 /* Don't return failure if kill() failed, because it may be a stale pid file */ 
     172                // Don't return failure if kill() failed, because it may be a stale pid file 
    176173        } 
    177174 
     
    184181                } 
    185182                osync_trace(TRACE_INTERNAL, "Waiting for other side to terminate"); 
    186                 /*FIXME: Magic numbers are evil */ 
     183                // FIXME: Magic numbers are evil 
    187184                g_usleep(500000); 
    188185        } 
     
    193190        } 
    194191 
    195         /* Success */ 
     192        // Success 
    196193        ret = TRUE; 
    197194 
     
    202199//out: 
    203200        return ret; 
    204 } 
    205 #endif 
     201}*/ 
     202 
    206203 
    207204/** This function takes care of the messages received on the outgoing (sending) 
     
    807804                proxy->outgoing = write1; 
    808805                proxy->incoming = read2; 
    809  
     806                 
    810807                /* Now we either spawn a new process, or we create a new thread */ 
    811808                if (type == OSYNC_START_TYPE_THREAD) { 
     
    830827                } else { 
    831828                        /* First lets see if the old plugin exists, and kill it if it does */ 
    832 #if 0                    
    833                         if (!_osync_client_kill_old_osplugin(proxy, error)) 
    834                                 goto error; 
    835 #endif                   
    836                          
     829                        //if (!_osync_client_kill_old_osplugin(proxy, error)) 
     830                        //      goto error; 
     831 
     832                        //if (!osync_queue_exists(proxy->outgoing) || !osync_queue_is_alive(proxy->outgoing)) { 
    837833                        if (!proxy->outgoing || !osync_queue_exists(proxy->outgoing) || !osync_queue_is_alive(proxy->outgoing)) { 
    838834                                pid_t cpid = fork(); 
    839835                                if (cpid == 0) { 
    840  
     836                                        osync_trace_reset_indent(); 
     837                                         
    841838                                        /* close the read and write ends of the pipes */ 
    842839                                        osync_queue_disconnect(write1, error); 
    843840                                        osync_queue_disconnect(read2, error); 
    844  
    845                                         osync_trace_reset_indent(); 
    846  
     841                                                 
     842                                        osync_trace(TRACE_INTERNAL, "About to exec osplugin"); 
     843                                        //char *memberstring = g_strdup_printf("%lli", osync_member_get_id(proxy->member)); 
     844                                        //execlp("osplugin", "osplugin", osync_group_get_configdir(osync_member_get_group(osync_proxy_get_member(proxy)), memberstring, NULL); 
    847845                                        char *readfd = g_strdup_printf("%i", osync_queue_get_fd(read1)); 
    848846                                        char *writefd = g_strdup_printf("%i", osync_queue_get_fd(write2)); 
    849                  
    850                                         osync_trace(TRACE_INTERNAL, "About to exec osplugin"); 
    851                                         execlp("osplugin", "osplugin", "-f", readfd, writefd,  NULL); 
    852                                          
     847                                        execlp("osplugin", "osplugin", "-f", readfd, writefd, NULL); 
     848 
    853849                                        if (errno == ENOENT) { 
    854850                                                osync_trace(TRACE_INTERNAL, "Unable to find osplugin. Trying local path."); 
     851                                                //execlp("osplugin", "osplugin", osync_group_get_configdir(osync_member_get_group(osync_proxy_get_member(proxy)), memberstring, NULL); 
    855852                                                execlp("./osplugin", "osplugin", "-f", readfd, writefd, NULL); 
    856853                                        } 
    857                                          
    858                                         g_free(readfd); 
    859                                         g_free(writefd); 
    860  
    861                                         osync_trace(TRACE_INTERNAL, "unable to exec"); 
     854                                                                                         
     855                                        osync_trace(TRACE_INTERNAL, strerror(errno)); 
     856                                        osync_trace(TRACE_INTERNAL, "Unable to execute osplugin."); 
    862857                                        exit(1); 
    863858                                } else { 
     
    866861                                        osync_queue_disconnect(read1, error); 
    867862                                } 
    868                 
     863         
    869864                                proxy->child_pid = cpid; 
    870                                  
    871                                 /* 
    872                                 while (!proxy->outgoing || !osync_queue_exists(proxy->outgoing)) { 
    873                                         osync_trace(TRACE_INTERNAL, "Waiting for other side to create fifo"); 
    874                                         g_usleep(500000); 
    875                                 } 
    876                                  
     865                         
     866                                //while (!osync_queue_exists(proxy->outgoing)) { 
     867                                //      osync_trace(TRACE_INTERNAL, "Waiting for other side to create fifo"); 
     868                                //      g_usleep(500000); 
     869                                //} 
     870                         
    877871                                osync_trace(TRACE_INTERNAL, "Queue was created"); 
    878  
    879                                 */ 
    880  
    881872                        } 
    882                  
    883                         /* 
    884                         if (proxy->child_pid) { 
    885                                 if (!_osync_client_create_pidfile(proxy, error)) 
    886                                         goto error; 
    887                         } 
    888                         */ 
     873         
     874                        //if (proxy->child_pid) { 
     875                        //      if (!_osync_client_create_pidfile(proxy, error)) 
     876                        //              goto error; 
     877                        //} 
    889878                } 
    890879                 
     
    957946                goto error; 
    958947        } 
    959          
    960948        osync_message_unref(message); 
    961949         
     
    969957                osync_client_unref(proxy->client); 
    970958        } else if (proxy->type == OSYNC_START_TYPE_PROCESS) { 
    971  
    972959                if (proxy->child_pid) { 
    973960                        int status; 
     
    982969                                osync_trace(TRACE_INTERNAL, "Child has returned non-zero exit status (%d)", WEXITSTATUS(status)); 
    983970 
    984 #if 0 
    985                         if (!osync_client_remove_pidfile(proxy, error)) 
    986                                 goto error; 
    987 #endif                   
     971                        //if (!osync_client_remove_pidfile(client, error)) 
     972                        //      goto error; 
    988973                } 
    989  
    990                  
    991974                 
    992975                /* First lets see if the old plugin exists, and kill it if it does */ 
    993 #if 0 
    994                 if (!_osync_client_kill_old_osplugin(proxy, error)) 
    995                         goto error; 
    996 #endif           
     976                //if (!_osync_client_kill_old_osplugin(proxy, error)) 
     977                //      goto error; 
    997978        } 
    998979                         
  • trunk/opensync/client/osplugin.c

    r2509 r2526  
    118118         
    119119        osync_client_unref(client); 
    120          
    121         osync_queue_free(incoming); 
    122         osync_queue_free(outgoing); 
     120 
     121        //queues are already freed with the client 
     122        //osync_queue_free(incoming); 
     123        //osync_queue_free(outgoing); 
    123124         
    124125        osync_trace(TRACE_EXIT, "%s", __func__); 
  • trunk/opensync/group/opensync_member_internals.h

    r2356 r2526  
    2929        char *configdata; 
    3030         
    31         OSyncGroup *group; 
     31        //OSyncGroup *group; 
    3232 
    3333        char *name; 
  • trunk/opensync/ipc/opensync_message.c

    r1197 r2526  
    246246/*@}*/ 
    247247 
     248char* osync_message_get_commandstr(OSyncMessage *message) 
     249{ 
     250        char* cmdstr = "UNKNOWN"; 
     251         
     252        switch(message->cmd) 
     253        { 
     254                case OSYNC_MESSAGE_NOOP: 
     255                        cmdstr = "OSYNC_MESSAGE_NOOP"; break; 
     256                case OSYNC_MESSAGE_CONNECT: 
     257                        cmdstr = "OSYNC_MESSAGE_CONNECT"; break; 
     258                case OSYNC_MESSAGE_DISCONNECT: 
     259                        cmdstr = "OSYNC_MESSAGE_DISCONNECT"; break; 
     260                case OSYNC_MESSAGE_GET_CHANGES: 
     261                        cmdstr = "OSYNC_MESSAGE_GET_CHANGES"; break; 
     262                case OSYNC_MESSAGE_READ_CHANGE: 
     263                        cmdstr = "OSYNC_MESSAGE_READ_CHANGE"; break; 
     264                case OSYNC_MESSAGE_COMMIT_CHANGE: 
     265                        cmdstr = "OSYNC_MESSAGE_COMMIT_CHANGE"; break; 
     266                case OSYNC_MESSAGE_COMMITTED_ALL: 
     267                        cmdstr = "OSYNC_MESSAGE_COMMITTED_ALL"; break; 
     268                case OSYNC_MESSAGE_SYNC_DONE: 
     269                        cmdstr = "OSYNC_MESSAGE_SYNC_DONE"; break; 
     270                case OSYNC_MESSAGE_CALL_PLUGIN: 
     271                        cmdstr = "OSYNC_MESSAGE_CALL_PLUGIN"; break; 
     272                case OSYNC_MESSAGE_NEW_CHANGE: 
     273                        cmdstr = "OSYNC_MESSAGE_NEW_CHANGE"; break; 
     274                case OSYNC_MESSAGE_REPLY: 
     275                        cmdstr = "OSYNC_MESSAGE_REPLY"; break; 
     276                case OSYNC_MESSAGE_ERRORREPLY: 
     277                        cmdstr = "OSYNC_MESSAGE_ERRORREPLY"; break; 
     278                case OSYNC_MESSAGE_INITIALIZE: 
     279                        cmdstr = "OSYNC_MESSAGE_INITIALIZE"; break; 
     280                case OSYNC_MESSAGE_FINALIZE: 
     281                        cmdstr = "OSYNC_MESSAGE_FINALIZE"; break; 
     282                case OSYNC_MESSAGE_DISCOVER: 
     283                        cmdstr = "OSYNC_MESSAGE_DISCOVER"; break; 
     284                case OSYNC_MESSAGE_SYNCHRONIZE: 
     285                        cmdstr = "OSYNC_MESSAGE_SYNCHRONIZE"; break; 
     286                case OSYNC_MESSAGE_ENGINE_CHANGED: 
     287                        cmdstr = "OSYNC_MESSAGE_ENGINE_CHANGED"; break; 
     288                case OSYNC_MESSAGE_MAPPING_CHANGED: 
     289                        cmdstr = "OSYNC_MESSAGE_MAPPING_CHANGED"; break; 
     290                case OSYNC_MESSAGE_MAPPINGENTRY_CHANGED: 
     291                        cmdstr = "OSYNC_MESSAGE_MAPPINGENTRY_CHANGED"; break; 
     292                case OSYNC_MESSAGE_ERROR: 
     293                        cmdstr = "OSYNC_MESSAGE_ERROR"; break; 
     294                case OSYNC_MESSAGE_QUEUE_ERROR: 
     295                        cmdstr = "OSYNC_MESSAGE_QUEUE_ERROR"; break; 
     296                case OSYNC_MESSAGE_QUEUE_HUP: 
     297                        cmdstr = "OSYNC_MESSAGE_QUEUE_HUP"; break; 
     298        } 
     299         
     300        return cmdstr;   
     301} 
     302 
    248303void osync_message_write_int(OSyncMessage *message, int value) 
    249304{ 
  • trunk/opensync/ipc/opensync_message.h

    r1974 r2526  
    7272osync_bool osync_message_send_with_timeout(OSyncMessage *message, OSyncQueue *queue, OSyncQueue *replyQueue, int timeout, OSyncError **error); 
    7373OSyncMessageCommand osync_message_get_command(OSyncMessage *message); 
     74char* osync_message_get_commandstr(OSyncMessage *message); 
    7475void osync_message_reset_timeout(OSyncMessage *message); 
    7576osync_bool osync_message_is_answered(OSyncMessage *message); 
  • trunk/opensync/ipc/opensync_queue.c

    r2510 r2526  
    22 * libosengine - A synchronization engine for the opensync framework 
    33 * Copyright (C) 2004-2005  Armin Bauer <armin.bauer@opensync.org> 
     4 * Copyright (C) 2007  Daniel Friedrich <daniel.friedrich@opensync.org> 
    45 *  
    56 * This library is free software; you can redistribute it and/or 
     
    6768        while ((message = g_async_queue_try_pop(queue->incoming))) { 
    6869                /* We check if the message is a reply to something */ 
    69                 osync_trace(TRACE_INTERNAL, "Dispatching %p:%i", message, osync_message_get_cmd(message)); 
     70                osync_trace(TRACE_INTERNAL, "Dispatching %p:%i(%s)", message, osync_message_get_cmd(message), osync_message_get_commandstr(message)); 
    7071                 
    7172                if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY || osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { 
     
    651652                } 
    652653                queue->fd = fd; 
    653                 int oldflags = fcntl(queue->fd, F_GETFD); 
    654                 if (oldflags == -1) { 
    655                         osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get fifo flags"); 
    656                         goto error_close; 
    657                 } 
    658                 if (fcntl(queue->fd, F_SETFD, oldflags|FD_CLOEXEC) == -1) { 
    659                         osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to set fifo flags"); 
    660                         goto error_close; 
    661                 } 
     654        } 
     655 
     656        int oldflags = fcntl(queue->fd, F_GETFD); 
     657        if (oldflags == -1) { 
     658                osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get fifo flags"); 
     659                goto error_close; 
     660        } 
     661        if (fcntl(queue->fd, F_SETFD, oldflags|FD_CLOEXEC) == -1) { 
     662                osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to set fifo flags"); 
     663                goto error_close; 
    662664        } 
    663665 
  • trunk/opensync/plugin/opensync_plugin_internals.h

    r2065 r2526  
    4444        OSyncStartType start_type; 
    4545        /** The pointer to the plugin (for internal use) */ 
    46         OSyncModule *module; 
     46        //OSyncModule *module; 
    4747        /** Plugin-specific data 
    4848         *