/* * GDMcommunication routines * (c)2001 Queen of England, (c)2002,2003 George Lebl * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gdm.h" #include "gdmcomm.h" #include "gdmcommon.h" #include "gdmconfig.h" static char *myname = NULL; /* name of this program */ static void usage () { fprintf (stderr, _("Usage: %s [-b][-v] and one of the following:\n"), myname); fprintf (stderr, _("\t-a display\n")); fprintf (stderr, _("\t-r display\n")); fprintf (stderr, _("\t-d display\n")); fprintf (stderr, _("\t-l [server_name]\n")); fprintf (stderr, _("\t-t maximum tries to connect (default 15)\n")); fprintf (stderr, _("\t-s sleep value (default 8)\n")); } /* * Note: gdmdynamic does work to deal with the socket being congested * because it is intended that the an umlimited number of gdmdynamic * requests could be made at any moment. It is the responsibility of * gdmdynamic to manage the socket connection to the daemon to make sure * that it does not starve the socket, especially since the GUI login * program will also be using the socket on startup. */ int main (int argc, char *argv[]) { gchar *cstr; gchar *version; gchar *params = ""; gchar *command = NULL; gchar *ret = NULL; gchar *cookie = NULL; int optc; int try_num = 0; int max_tries = 15; int sleep_val = 8; int verbose = 0; int background = 0; gboolean error = TRUE; gboolean conn_failed = FALSE; gboolean gdm_running; myname = basename (argv[0]); argv[0] = myname; version = "2.8.0.0"; while ((optc = getopt (argc, argv, "a:d:r:t:s:blv")) != EOF) { switch (optc) { case 'a': if (command == NULL) error = FALSE; command = GDM_SUP_ADD_DYNAMIC_DISPLAY; params = optarg; break; case 'b': background = 1; break; case 'd': if (command == NULL) error = FALSE; command = GDM_SUP_REMOVE_DYNAMIC_DISPLAY; params = optarg; break; case 'l': if (command == NULL) error = FALSE; command = GDM_SUP_ATTACHED_SERVERS; break; case 'r': if (command == NULL) error = FALSE; command = GDM_SUP_RELEASE_DYNAMIC_DISPLAYS; params = optarg; break; case 't': max_tries = atoi (optarg); break; case 's': sleep_val = atoi (optarg); break; case 'v': verbose++; break; case '?': error = TRUE; } } if (error) { usage (); exit (1); } /* process remaining option arguments for -l */ if (command == GDM_SUP_ATTACHED_SERVERS) for (; optind 0) rand_sleep = ((int) ((rand () % 10)/2)) + sleep_val; if (verbose) { g_print (_("Connection to daemon failed, sleeping for %d seconds. Retry %d of %d\n"), rand_sleep, try_num, max_tries); } sleep (rand_sleep); /* Reset the connection failed flag so it can be tried again */ gdmcomm_set_allow_sleep (TRUE); } } while ((conn_failed == TRUE) && (try_num < max_tries)); g_free (cstr); if (cookie) g_free (cookie); /* * If we failed to connect to the daemon after trying a certain number of * times, then return with code 2 to let the caller know that the failure * was due to connection problems. The caller can decide to perhaps * sleep a bit an try this command again. */ if (conn_failed == TRUE) { /* This is a serious error, so print a message even if verbose is off */ fprintf (stderr, _("Failed to connect to server after %d retries\n"), try_num); return 2; } if (verbose && ret != NULL) g_print ("%s\n", ret); if (ret != NULL && strncmp (ret, "OK", 2) == 0) { if (strcmp (command, GDM_SUP_ATTACHED_SERVERS) == 0) { ret += 2; if (strlen (ret)) { ret++; /* skip over space char */ g_print ("%s\n", ret); } } /* Success! */ return 0; } return 1; }