1
/* $Xorg: lock.c,v 1.4 2001/02/09 02:05:59 xorgcvs Exp $ */
2
/******************************************************************************
4
Copyright 1994, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
25
******************************************************************************/
26
/* $XFree86: xc/programs/xsm/lock.c,v 3.5 2002/05/31 18:46:14 dawes Exp $ */
31
#include <sys/types.h>
37
char *path = (char *) getenv ("SM_SAVE_DIR");
41
path = (char *) getenv ("HOME");
51
LockSession(char *session_name, Bool write_id)
54
char lock_file[PATH_MAX];
55
char temp_lock_file[PATH_MAX];
62
sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
63
sprintf (temp_lock_file, "%s/.XSMtlock-%s", path, session_name);
65
sprintf (temp_lock_file, "%s/%s.slk", path, session_name);
68
if ((fd = creat (temp_lock_file, 0444)) < 0)
72
(write (fd, networkIds, strlen (networkIds)) != strlen (networkIds))) ||
73
(write (fd, "\n", 1) != 1))
84
if (link (temp_lock_file, lock_file) < 0)
87
if (unlink (temp_lock_file) < 0)
98
UnlockSession(char *session_name)
101
char lock_file[PATH_MAX];
105
sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
112
GetLockId(char *session_name)
116
char lock_file[PATH_MAX];
122
sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
124
if ((fp = fopen (lock_file, "r")) == NULL)
130
fscanf (fp, "%s\n", buf);
131
ret = XtNewString (buf);
140
CheckSessionLocked(char *session_name, Bool get_id, char **id_ret)
143
*id_ret = GetLockId (session_name);
145
if (!LockSession (session_name, False))
148
UnlockSession (session_name);
154
UnableToLockSession(char *session_name)
157
* We should popup a dialog here giving error.
161
XkbStdBell(XtDisplay(topLevel),XtWindow(topLevel),0,XkbBI_Failure);
163
XBell (XtDisplay (topLevel), 0);