summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:48:58 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:48:58 +0000
commit2a637a09ff68246161945821392656492f1fbde1 (patch)
treed515711c9476997088e583fe4a737d5c7e67df1b
parentf4d5033f594bf278ff1171091219b3c28dc45446 (diff)
-rw-r--r--save.c72
-rw-r--r--smproxy.c63
-rw-r--r--smproxy.h27
-rw-r--r--smproxy.man5
4 files changed, 121 insertions, 46 deletions
diff --git a/save.c b/save.c
index 5a0b8d1..c594b84 100644
--- a/save.c
+++ b/save.c
@@ -25,32 +25,33 @@ in this Software without prior written authorization from The Open Group.
Author: Ralph Mor, X Consortium
******************************************************************************/
+/* $XFree86: xc/programs/smproxy/save.c,v 1.8 2001/12/14 20:01:05 dawes Exp $ */
#include "smproxy.h"
+#ifdef HAS_MKSTEMP
+#include <unistd.h>
+#endif
-typedef struct ProxyFileEntry
-{
- struct ProxyFileEntry *next;
- int tag;
- char *client_id;
- XClassHint class;
- char *wm_name;
- int wm_command_count;
- char **wm_command;
-} ProxyFileEntry;
ProxyFileEntry *proxyFileHead = NULL;
extern WinInfo *win_head;
+static int write_byte ( FILE *file, unsigned char b );
+static int write_short ( FILE *file, unsigned short s );
+static int write_counted_string ( FILE *file, char *string );
+static int read_byte ( FILE *file, unsigned char *bp );
+static int read_short ( FILE *file, unsigned short *shortp );
+static int read_counted_string ( FILE *file, char **stringp );
+#ifndef HAS_MKSTEMP
+static char * unique_filename ( char *path, char *prefix );
+#else
+static char * unique_filename ( char *path, char *prefix, int *pFd );
+#endif
static int
-write_byte (file, b)
-
-FILE *file;
-unsigned char b;
-
+write_byte (FILE *file, unsigned char b)
{
if (fwrite ((char *) &b, 1, 1, file) != 1)
return 0;
@@ -59,11 +60,7 @@ unsigned char b;
static int
-write_short (file, s)
-
-FILE *file;
-unsigned short s;
-
+write_short (FILE *file, unsigned short s)
{
unsigned char file_short[2];
@@ -224,7 +221,7 @@ ProxyFileEntry **pentry;
{
ProxyFileEntry *entry;
- char byte;
+ unsigned char byte;
int i;
*pentry = entry = (ProxyFileEntry *) malloc (
@@ -333,13 +330,21 @@ char *filename;
+#ifndef HAS_MKSTEMP
static char *
unique_filename (path, prefix)
-
char *path;
char *prefix;
+#else
+static char *
+unique_filename (path, prefix, pFd)
+char *path;
+char *prefix;
+int *pFd;
+#endif
{
+#ifndef HAS_MKSTEMP
#ifndef X_NOT_POSIX
return ((char *) tempnam (path, prefix));
#else
@@ -357,6 +362,19 @@ char *prefix;
else
return (NULL);
#endif
+#else
+ char tempFile[PATH_MAX];
+ char *ptr;
+
+ sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
+ ptr = (char *)malloc(strlen(tempFile) + 1);
+ if (ptr != NULL)
+ {
+ strcpy(ptr, tempFile);
+ *pFd = mkstemp(ptr);
+ }
+ return ptr;
+#endif
}
@@ -367,6 +385,9 @@ WriteProxyFile ()
{
FILE *proxyFile = NULL;
char *filename = NULL;
+#ifdef HAS_MKSTEMP
+ int fd;
+#endif
char *path;
WinInfo *winptr;
Bool success = False;
@@ -379,12 +400,19 @@ WriteProxyFile ()
path = ".";
}
+#ifndef HAS_MKSTEMP
if ((filename = unique_filename (path, ".prx")) == NULL)
goto bad;
if (!(proxyFile = fopen (filename, "wb")))
goto bad;
+#else
+ if ((filename = unique_filename (path, ".prx", &fd)) == NULL)
+ goto bad;
+ if (!(proxyFile = fdopen(fd, "wb")))
+ goto bad;
+#endif
if (!write_short (proxyFile, SAVEFILE_VERSION))
goto bad;
diff --git a/smproxy.c b/smproxy.c
index 41ed45a..a416465 100644
--- a/smproxy.c
+++ b/smproxy.c
@@ -25,8 +25,11 @@ in this Software without prior written authorization from The Open Group.
Author: Ralph Mor, X Consortium
******************************************************************************/
+/* $XFree86: xc/programs/smproxy/smproxy.c,v 3.9 2001/12/14 20:01:05 dawes Exp $ */
#include "smproxy.h"
+#include <unistd.h>
+#include <X11/Xmu/WinUtil.h>
XtAppContext appContext;
Display *disp;
@@ -57,6 +60,39 @@ Bool sent_save_done = 0;
int Argc;
char **Argv;
+Bool HasSaveYourself ( Window window );
+Bool HasXSMPsupport ( Window window );
+WinInfo * GetClientLeader ( WinInfo *winptr );
+char * CheckFullyQuantifiedName ( char *name, int *newstring );
+void FinishSaveYourself ( WinInfo *winInfo, Bool has_WM_SAVEYOURSELF );
+void SaveYourselfCB ( SmcConn smcConn, SmPointer clientData, int saveType,
+ Bool shutdown, int interactStyle, Bool fast );
+void DieCB ( SmcConn smcConn, SmPointer clientData );
+void SaveCompleteCB ( SmcConn smcConn, SmPointer clientData );
+void ShutdownCancelledCB ( SmcConn smcConn, SmPointer clientData );
+void ProcessIceMsgProc ( XtPointer client_data, int *source, XtInputId *id );
+void NullIceErrorHandler ( IceConn iceConn, Bool swap,
+ int offendingMinorOpCode,
+ unsigned long offendingSequence,
+ int errorClass, int severity, IcePointer values );
+void ConnectClientToSM ( WinInfo *winInfo );
+int MyErrorHandler ( Display *display, XErrorEvent *event );
+Bool LookupWindow ( Window window, WinInfo **ptr_ret, WinInfo **prev_ptr_ret );
+WinInfo * AddNewWindow ( Window window );
+void RemoveWindow ( WinInfo *winptr );
+void Got_WM_STATE ( WinInfo *winptr );
+void HandleCreate ( XCreateWindowEvent *event );
+void HandleDestroy ( XDestroyWindowEvent *event );
+void HandleUpdate ( XPropertyEvent *event );
+void ProxySaveYourselfPhase2CB ( SmcConn smcConn, SmPointer clientData );
+void ProxySaveYourselfCB ( SmcConn smcConn, SmPointer clientData,
+ int saveType, Bool shutdown, int interactStyle,
+ Bool fast );
+void ProxyDieCB ( SmcConn smcConn, SmPointer clientData );
+void ProxySaveCompleteCB ( SmcConn smcConn, SmPointer clientData );
+void ProxyShutdownCancelledCB ( SmcConn smcConn, SmPointer clientData );
+Status ConnectProxyToSM ( char *previous_id );
+void CheckForExistingWindows ( Window root );
Bool
@@ -237,7 +273,7 @@ Bool has_WM_SAVEYOURSELF;
prop1val.value = (SmPointer) winInfo->wm_command[0];
prop1val.length = strlen (winInfo->wm_command[0]);
- sprintf (userId, "%d", getuid());
+ sprintf (userId, "%ld", (long)getuid());
prop2.name = SmUserID;
prop2.type = SmARRAY8;
prop2.num_vals = 1;
@@ -347,7 +383,8 @@ Bool fast;
if (debug)
{
- printf ("Sent SAVE YOURSELF to 0x%x\n", winInfo->window);
+ printf ("Sent SAVE YOURSELF to 0x%x\n",
+ (unsigned int)winInfo->window);
printf ("\n");
}
}
@@ -356,7 +393,7 @@ Bool fast;
if (debug)
{
printf ("Failed to send SAVE YOURSELF to 0x%x\n",
- winInfo->window);
+ (unsigned int)winInfo->window);
printf ("\n");
}
}
@@ -381,7 +418,7 @@ SmPointer clientData;
/* Now tell the client to die */
if (debug)
- printf ("Trying to kill 0x%x\n", winInfo->window);
+ printf ("Trying to kill 0x%x\n", (unsigned int)winInfo->window);
XSync (disp, 0);
XKillClient (disp, winInfo->window);
@@ -529,7 +566,8 @@ WinInfo *winInfo;
if (debug)
{
- printf ("Connected to SM, window = 0x%x\n", winInfo->window);
+ printf ("Connected to SM, window = 0x%x\n",
+ (unsigned int)winInfo->window);
printf ("\n");
}
@@ -538,6 +576,7 @@ WinInfo *winInfo;
+int
MyErrorHandler (display, event)
Display *display;
@@ -545,6 +584,7 @@ XErrorEvent *event;
{
caught_error = 1;
+ return 0;
}
@@ -866,7 +906,8 @@ XDestroyWindowEvent *event;
if (debug)
{
- printf ("Removed window (window = 0x%x)\n", winptr->window);
+ printf ("Removed window (window = 0x%x)\n",
+ (unsigned int)winptr->window);
printf ("\n");
}
@@ -941,7 +982,7 @@ SmPointer clientData;
prop1val.value = Argv[0];
prop1val.length = strlen (Argv[0]);
- sprintf (userId, "%d", getuid());
+ sprintf (userId, "%ld", (long)getuid());
prop2.name = SmUserID;
prop2.type = SmARRAY8;
prop2.num_vals = 1;
@@ -1211,11 +1252,8 @@ Window root;
-main (argc, argv)
-
-int argc;
-char **argv;
-
+int
+main (int argc, char *argv[])
{
char *restore_filename = NULL;
char *client_id = NULL;
@@ -1311,4 +1349,5 @@ char **argv;
break;
}
}
+ exit(0);
}
diff --git a/smproxy.h b/smproxy.h
index a6e7522..ce58ff0 100644
--- a/smproxy.h
+++ b/smproxy.h
@@ -25,6 +25,7 @@ in this Software without prior written authorization from The Open Group.
Author: Ralph Mor, X Consortium
******************************************************************************/
+/* $XFree86: xc/programs/smproxy/smproxy.h,v 1.6 2001/12/14 20:01:05 dawes Exp $ */
#include <X11/Xosdefs.h>
#include <X11/Xfuncs.h>
@@ -42,13 +43,7 @@ Author: Ralph Mor, X Consortium
#else
#include <stdio.h>
#endif
-
-#ifndef X_NOT_STDC_ENV
#include <stdlib.h>
-#else
-extern char *malloc(), *calloc(), *realloc(), *getenv();
-extern void free();
-#endif
#ifndef X_NOT_POSIX
#ifdef _POSIX_SOURCE
@@ -90,12 +85,22 @@ typedef struct WinInfo {
} WinInfo;
+typedef struct ProxyFileEntry
+{
+ struct ProxyFileEntry *next;
+ int tag;
+ char *client_id;
+ XClassHint class;
+ char *wm_name;
+ int wm_command_count;
+ char **wm_command;
+} ProxyFileEntry;
-extern int WriteProxyFileEntry ();
-extern int ReadProxyFileEntry ();
-extern void ReadProxyFile ();
-extern char *WriteProxyFile ();
-extern char *LookupClientID ();
+extern int WriteProxyFileEntry ( FILE *proxyFile, WinInfo *theWindow );
+extern int ReadProxyFileEntry ( FILE *proxyFile, ProxyFileEntry **pentry );
+extern void ReadProxyFile ( char *filename );
+extern char * WriteProxyFile ( void );
+extern char * LookupClientID ( WinInfo *theWindow );
#define SAVEFILE_VERSION 1
diff --git a/smproxy.man b/smproxy.man
index 0c1c355..d18650d 100644
--- a/smproxy.man
+++ b/smproxy.man
@@ -22,7 +22,10 @@
.\" not be used in advertising or otherwise to promote the sale, use or
.\" other dealings in this Software without prior written authorization
.\" from The Open Group.
-.TH XSM 1 "Release 6.4" "X Version 11"
+.\"
+.\" $XFree86: xc/programs/smproxy/smproxy.man,v 1.7 2001/12/14 20:01:05 dawes Exp $
+.\"
+.TH XSM 1 __xorgversion__
.SH NAME
smproxy \- Session Manager Proxy
.SH SYNOPSIS