No protocol specified error



Hello,

I am using simple program

#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
    GtkWidget *window;
    gtk_init(NULL, NULL);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_show(window);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    gtk_main();
    return 0;
}

I compiled it using gcc simple.c `pkg-config --cflags gtk+-3.0 --libs`
if I do ./a.out, GUI is showing up.

but if I do "sudo ./a.out", I am seeing the following error :

================================================
$ sudo ./a.out
No protocol specified
Unable to init server: Could not connect: Connection refused

(a.out:7961): Gtk-WARNING **: cannot open display: :0
================================================

As my application back end needs root privileges, I need to open the GUI
using sudo only.
Can some one help in fixing this issue ?

The same code was working fine in Ubuntu 17.04. But I am facing this issue
after upgrading to Ubuntu 17.10.

Thanks
--
Lokesh Chakka,
Mobile: 9731023458


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