#include #include "globals.h" #include "ncpwrapper.h" #include "dialogs.h" gboolean mounted = TRUE; static void cb_child_watch( GPid pid, gint status) { /* Close pid */ g_spawn_close_pid( pid ); } static gboolean cb_out_watch( GIOChannel *channel, GIOCondition cond) { GString *string; gchar *tmp; gsize size; if( cond == G_IO_HUP ) { g_io_channel_unref( channel ); return( FALSE ); } string = g_string_new(""); while (g_io_channel_read_line( channel, &tmp, &size, NULL, NULL) == G_IO_STATUS_NORMAL) { if(tmp != NULL) string = g_string_append (string, tmp); g_free( tmp ); } /* Receved some message - not mounted */ mounted = FALSE; show_message( GTK_MESSAGE_INFO,"%s", "ncpmount output","%s",string->str); g_string_free(string, TRUE); return( TRUE ); } static gboolean cb_err_watch( GIOChannel *channel, GIOCondition cond) { GString *string; gchar *tmp; gsize size; if( cond == G_IO_HUP ) { g_io_channel_unref( channel ); /* hangup signal - if mounted then show message */ if(mounted) show_message( GTK_MESSAGE_INFO,"Mounting succesfull", "","Mounted to \"%s\" directory.",cmd_params.mount_point); return( FALSE ); } /* g_io_channel_read_line( channel, &string, &size, NULL, NULL ); show_message( GTK_MESSAGE_ERROR,"ERROR: %s", string,"%s",string); puts ("err"); puts (string); g_free( string );*/ string = g_string_new(""); while (g_io_channel_read_line( channel, &tmp, &size, NULL, NULL) == G_IO_STATUS_NORMAL) { if(tmp != NULL) string = g_string_append (string, tmp); g_free( tmp ); } /* Receved some message - not mounted */ mounted = FALSE; show_message( GTK_MESSAGE_ERROR,"%s", "ncpmount error","%s",string->str); g_string_free(string, TRUE); return( TRUE ); } void run_ncpmount() { GIOChannel *out_ch, *err_ch; GError *gerror = NULL; GPid pid; gint out, err; gboolean ret; gchar *command = get_ncpmount_command(NULL); gchar **argv = g_strsplit(command, " ", 0); puts (command); g_free(argv[0]); argv[0] = g_strdup("/usr/bin/ncpmount"); /* gchar *argv[] = {"/usr/bin/ncpmount", "-v", NULL};*/ mounted = TRUE; /* Spawn child process */ ret = g_spawn_async_with_pipes( NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL, &out, &err, &gerror); if( !ret ) { g_warning( "SPAWN FAILED" ); show_message( GTK_MESSAGE_ERROR,"ERROR: %s", "Spawn failed!","%s",gerror->message); g_error_free(gerror); return; } /* Add watch function to catch termination of the process. This function * will clean any remnants of process. */ g_child_watch_add( pid, (GChildWatchFunc)cb_child_watch, NULL); /* Create channels that will be used to read data from pipes. */ #ifdef G_OS_WIN32 out_ch = g_io_channel_win32_new_fd( out ); err_ch = g_io_channel_win32_new_fd( err ); #else out_ch = g_io_channel_unix_new( out ); err_ch = g_io_channel_unix_new( err ); #endif /* Add watches to channels */ g_io_add_watch( err_ch, G_IO_IN | G_IO_HUP, (GIOFunc)cb_err_watch, NULL ); g_io_add_watch( out_ch, G_IO_IN | G_IO_HUP, (GIOFunc)cb_out_watch, NULL ); g_strfreev(argv); g_free(command); }