author | Jon Tibble <meths@btinternet.com> |
Thu, 09 Dec 2010 22:32:39 +0100 | |
changeset 13255 | 4afa820d78b9 |
parent 6812 | febeba71273d |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1914
8a8c5f225b1b
4916205 libcmd should not use file operation routines from C library
casper
parents:
0
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
8a8c5f225b1b
4916205 libcmd should not use file operation routines from C library
casper
parents:
0
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
0 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
21 |
|
0 | 22 |
/* |
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
23 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
0 | 24 |
* Use is subject to license terms. |
25 |
*/ |
|
26 |
||
27 |
/* Copyright (c) 1988 AT&T */ |
|
28 |
/* All Rights Reserved */ |
|
29 |
||
6812 | 30 |
#pragma ident "%Z%%M% %I% %E% SMI" |
31 |
||
0 | 32 |
/* |
33 |
* Return the number of the slot in the utmp file |
|
34 |
* corresponding to the current user: try for file 0, 1, 2. |
|
35 |
* Returns -1 if slot not found. |
|
36 |
*/ |
|
37 |
||
6812 | 38 |
#include "lint.h" |
0 | 39 |
#include <string.h> |
40 |
#include <stdio.h> |
|
41 |
#include <sys/types.h> |
|
42 |
#include <sys/stat.h> |
|
43 |
#include <unistd.h> |
|
44 |
#include <utmpx.h> |
|
45 |
#include <stdlib.h> |
|
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
46 |
#include <pthread.h> |
0 | 47 |
|
48 |
#ifndef TRUE |
|
49 |
#define TRUE 1 |
|
50 |
#define FALSE 0 |
|
51 |
#endif |
|
52 |
||
53 |
int |
|
54 |
ttyslot(void) |
|
55 |
{ |
|
56 |
struct futmpx ubuf; |
|
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
57 |
char *p; |
0 | 58 |
int s; |
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
59 |
int ret = -1; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
60 |
int console = FALSE; |
0 | 61 |
char ttynm[128]; |
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
62 |
FILE *fp; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
63 |
int cancel_state; |
0 | 64 |
|
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
65 |
/* |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
66 |
* The UNIX98 Posix conformance test suite requires |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
67 |
* ttyslot() to not be a cancellation point. |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
68 |
*/ |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
69 |
(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); |
0 | 70 |
|
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
71 |
if ((p = ttyname_r(0, ttynm, 128)) != NULL || |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
72 |
(p = ttyname_r(1, ttynm, 128)) != NULL || |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
73 |
(p = ttyname_r(2, ttynm, 128)) != NULL) { |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
74 |
if (strncmp(p, "/dev/", 5) == 0) |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
75 |
p += 5; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
76 |
if (strcmp(p, "console") == 0) |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
77 |
console = TRUE; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
78 |
s = 0; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
79 |
if ((fp = fopen(UTMPX_FILE, "rF")) != NULL) { |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
80 |
while ((fread(&ubuf, sizeof (ubuf), 1, fp)) == 1) { |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
81 |
if ((ubuf.ut_type == INIT_PROCESS || |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
82 |
ubuf.ut_type == LOGIN_PROCESS || |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
83 |
ubuf.ut_type == USER_PROCESS) && |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
84 |
strncmp(p, ubuf.ut_line, |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
85 |
sizeof (ubuf.ut_line)) == 0) { |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
86 |
ret = s; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
87 |
if (!console || |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
88 |
strncmp(ubuf.ut_host, ":0", 2) == 0) |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
89 |
break; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
90 |
} |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
91 |
s++; |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
92 |
} |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
93 |
(void) fclose(fp); |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
94 |
} |
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
95 |
} |
0 | 96 |
|
6737
5fd01d0533f4
6697956 UNIX98: *vsth* pthread_cancel fails in wordexp(), cuserid(), ttyslot()
raf
parents:
1914
diff
changeset
|
97 |
(void) pthread_setcancelstate(cancel_state, NULL); |
0 | 98 |
return (ret); |
99 |
} |