Changeset 2511

Show
Ignore:
Timestamp:
09/02/07 18:11:41 (1 year ago)
Author:
dgollub
Message:

Reimplementation of OSYNC_START_TYPE_PROCESS - which allows plugins to
run in a seperate process. This is needed for certain plugins like
kdepim-sync when using GUIs like KitchenSync?, MultiSync?, ....

See http://www.opensync.org/wiki/IPC for more details.

To run your plugin in a seperate process run:

osync_plugin_set_start_type(plugin, OSYNC_START_TYPE_PROCESS);

in the get_sync_info() function.

Implementation details:

osplugin got now called as "osplugin -f X Y".
X and Y are the read and write file descriptor for the pipes. We used to
have some pid files to track and kill them - is this still needed? Could
we got rid of this implemenetation?

TODO: Evalute if the osplugin.pid needs to be implemented
FIXME: No HUP signal got send to the forked client process.. so it
never got stopped -> deadlock.

Files:

Legend:

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

    r2488 r2511  
    3535 
    3636#include <sys/types.h> 
     37#include <sys/wait.h> 
    3738#include <signal.h> 
    3839 
     
    7879 
    7980//portable kill pid helper 
     81#if 0 
    8082static int _osync_kill(pid_t pid, int sig)  
    8183{ 
     
    106108#endif //_WIN32 
    107109}  
    108  
     110#endif 
     111 
     112#if 0 
    109113static char *_osync_client_pid_filename(OSyncClientProxy *proxy) 
    110114{ 
     
    112116} 
    113117 
    114 /*static osync_bool osync_client_remove_pidfile(OSyncClientProxy *proxy, OSyncError **error) 
     118static osync_bool osync_client_remove_pidfile(OSyncClientProxy *proxy, OSyncError **error) 
    115119{ 
    116120        char *pidpath = _osync_client_pid_filename(proxy); 
     
    140144        g_free(pidpath); 
    141145        return TRUE; 
    142 }*/ 
     146} 
    143147 
    144148static osync_bool _osync_client_kill_old_osplugin(OSyncClientProxy *proxy, OSyncError **error) 
     
    199203        return ret; 
    200204} 
     205#endif 
    201206 
    202207/** This function takes care of the messages received on the outgoing (sending) 
     
    800805                        goto error_free_pipe1; 
    801806                 
     807                proxy->outgoing = write1; 
     808                proxy->incoming = read2; 
     809 
    802810                /* Now we either spawn a new process, or we create a new thread */ 
    803811                if (type == OSYNC_START_TYPE_THREAD) { 
     
    822830                } else { 
    823831                        /* First lets see if the old plugin exists, and kill it if it does */ 
     832#if 0                    
    824833                        if (!_osync_client_kill_old_osplugin(proxy, error)) 
    825834                                goto error; 
    826                          
    827                         /*todo*/ 
    828                          
    829                          
    830                  
    831                 /*if (!osync_queue_exists(proxy->outgoing) || !osync_queue_is_alive(proxy->outgoing)) { 
    832                         pid_t cpid = fork(); 
    833                         if (cpid == 0) { 
    834                                 osync_trace_reset_indent(); 
    835          
    836                                 osync_trace(TRACE_INTERNAL, "About to exec osplugin"); 
    837                                 char *memberstring = g_strdup_printf("%lli", osync_member_get_id(proxy->member)); 
    838                                 execlp("osplugin", "osplugin", osync_group_get_configdir(engine->group), memberstring, NULL); 
     835#endif                   
     836                         
     837                        if (!proxy->outgoing || !osync_queue_exists(proxy->outgoing) || !osync_queue_is_alive(proxy->outgoing)) { 
     838                                pid_t cpid = fork(); 
     839                                if (cpid == 0) { 
     840                                        osync_trace_reset_indent(); 
     841 
     842                                        char *readfd = g_strdup_printf("%i", osync_queue_get_fd(read1)); 
     843                                        char *writefd = g_strdup_printf("%i", osync_queue_get_fd(write2)); 
     844                 
     845                                        osync_trace(TRACE_INTERNAL, "About to exec osplugin"); 
     846                                        execlp("osplugin", "osplugin", "-f", readfd, writefd,  NULL); 
     847                                         
     848                                        if (errno == ENOENT) { 
     849                                                osync_trace(TRACE_INTERNAL, "Unable to find osplugin. Trying local path."); 
     850                                                execlp("./osplugin", "osplugin", "-f", readfd, writefd, NULL); 
     851                                        } 
     852                                         
     853                                        g_free(readfd); 
     854                                        g_free(writefd); 
     855 
     856                                        osync_trace(TRACE_INTERNAL, "unable to exec"); 
     857                                        exit(1); 
     858                                } 
     859                 
     860                                proxy->child_pid = cpid; 
    839861                                 
    840                                 if (errno == ENOENT) { 
    841                                         osync_trace(TRACE_INTERNAL, "Unable to find osplugin. Trying local path."); 
    842                                         execlp("./osplugin", "osplugin", osync_group_get_configdir(engine->group), memberstring, NULL); 
     862                                /* 
     863                                while (!proxy->outgoing || !osync_queue_exists(proxy->outgoing)) { 
     864                                        osync_trace(TRACE_INTERNAL, "Waiting for other side to create fifo"); 
     865                                        g_usleep(500000); 
    843866                                } 
    844867                                 
    845                                 osync_trace(TRACE_INTERNAL, "unable to exec"); 
    846                                 exit(1); 
     868                                osync_trace(TRACE_INTERNAL, "Queue was created"); 
     869 
     870                                */ 
     871 
    847872                        } 
    848          
    849                         proxy->child_pid = cpid; 
    850                          
    851                         while (!osync_queue_exists(proxy->outgoing)) { 
    852                                 osync_trace(TRACE_INTERNAL, "Waiting for other side to create fifo"); 
    853                                 g_usleep(500000); 
     873                 
     874                        /* 
     875                        if (proxy->child_pid) { 
     876                                if (!_osync_client_create_pidfile(proxy, error)) 
     877                                        goto error; 
    854878                        } 
    855                          
    856                         osync_trace(TRACE_INTERNAL, "Queue was created"); 
     879                        */ 
    857880                } 
    858          
    859                 if (proxy->child_pid) { 
    860                         if (!_osync_client_create_pidfile(proxy, error)) 
    861                                 goto error; 
    862                 }*/ 
    863                 } 
    864                  
    865                 proxy->outgoing = write1; 
    866                 proxy->incoming = read2; 
    867          
     881                 
    868882                /* We now connect to our incoming queue */ 
    869883                if (!osync_queue_connect(proxy->incoming, OSYNC_QUEUE_RECEIVER, error)) 
     
    946960                osync_client_unref(proxy->client); 
    947961        } else if (proxy->type == OSYNC_START_TYPE_PROCESS) { 
    948                 /*if (client->child_pid) { 
    949                 int status; 
    950                 if (waitpid(client->child_pid, &status, 0) == -1) { 
    951                         osync_error_set(error, OSYNC_ERROR_GENERIC, "Error waiting for osplugin process: %s", g_strerror(errno)); 
    952                         goto error; 
     962 
     963                if (proxy->child_pid) { 
     964                        int status; 
     965                        if (waitpid(proxy->child_pid, &status, 0) == -1) { 
     966                                osync_error_set(error, OSYNC_ERROR_GENERIC, "Error waiting for osplugin process: %s", g_strerror(errno)); 
     967                                goto error; 
     968                        } 
     969 
     970                        if (!WIFEXITED(status)) 
     971                                osync_trace(TRACE_INTERNAL, "Child has exited abnormally"); 
     972                        else if (WEXITSTATUS(status) != 0) 
     973                                osync_trace(TRACE_INTERNAL, "Child has returned non-zero exit status (%d)", WEXITSTATUS(status)); 
     974 
     975#if 0 
     976                        if (!osync_client_remove_pidfile(proxy, error)) 
     977                                goto error; 
     978#endif                   
    953979                } 
    954980 
    955                 if (!WIFEXITED(status)) 
    956                         osync_trace(TRACE_INTERNAL, "Child has exited abnormally"); 
    957                 else if (WEXITSTATUS(status) != 0) 
    958                         osync_trace(TRACE_INTERNAL, "Child has returned non-zero exit status (%d)", WEXITSTATUS(status)); 
    959  
    960                 if (!osync_client_remove_pidfile(client, error)) 
    961                         goto error; 
    962         }*/ 
    963981                 
    964982                 
    965983                /* First lets see if the old plugin exists, and kill it if it does */ 
     984#if 0 
    966985                if (!_osync_client_kill_old_osplugin(proxy, error)) 
    967986                        goto error; 
     987#endif           
    968988        } 
    969989