glib question about g_io_add_watch_full



i'm try to execute /etc/init.d/sshd status with g_spawn_async_with_pipes
and g_io_add_watch_full

spawn_asycn works, but g_io_add_watch_full does not, where is my
mistake, can You help me?

char *argv[3];
argv[0] = "/etc/init.d/sshd";
argv[1] = "status";
argv[2] = NULL;
exec (argv);


gboolean exec (gchar **argv) {
        GIOChannel *channel_out;
        GIOChannel *channel_in;
        GIOChannel *channel_err;

        gint std_in;
        gint std_out;
        gint std_err;
        guint std_in_out;
        guint std_in_err;
        GError *error = NULL;

        channel_out = g_io_channel_unix_new(1);
        channel_err = g_io_channel_unix_new(2);

        if (g_spawn_async_with_pipes ("/", argv, NULL,
G_SPAWN_LEAVE_DESCRIPTORS_OPEN, NULL, NULL, NULL, &std_in, &std_out,
&std_err, &error)) {
                std_in_out = g_io_add_watch_full(channel_out,
G_PRIORITY_LOW, GIOCondition (G_IO_IN | G_IO_OUT | G_IO_PRI | G_IO_ERR |
G_IO_HUP | G_IO_NVAL), exec_read, NULL, NULL);
                std_in_err = g_io_add_watch_full(channel_err,
G_PRIORITY_LOW, GIOCondition (G_IO_IN | G_IO_OUT | G_IO_PRI | G_IO_ERR |
G_IO_HUP | G_IO_NVAL), exec_read, NULL, NULL);
                std::cerr << "spawn!" << std::endl;
        }
        else {
                std::cerr << "FUCK" << std::endl;
                std::cerr << error->message << std::endl;
        }
        return 0;
}


gboolean exec_read (GIOChannel *iochannel, GIOCondition condition,
gpointer data) {
        gchar *buffer = NULL;
        gsize bytes = 0;
        GError *error = NULL;
        g_io_channel_set_encoding (iochannel, NULL, NULL);

        if (condition ) {
                if (g_io_channel_read_to_end (iochannel, &buffer,
&bytes, &error) == G_IO_STATUS_NORMAL ) {
                        std::cerr << buffer << std::endl;
                        std::cerr << "error" << std::endl;
                        std::cerr << error->message << std::endl;
                }
                else {
                        std::cerr << "error" << std::endl;
                        std::cerr << error->message << std::endl;
                        std::cerr << buffer << std::endl;
                }
        }
        g_io_channel_shutdown (iochannel, TRUE, NULL);
        g_io_channel_unref (iochannel);
        return 0;
}


-- 
Vasiliy G Tolstov <v tolstov selfip ru>
Selfip.Ru




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]