00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #define LIBIPC
00039 #if 0
00040 #include "ipcmsg.h"
00041 #endif
00042 #include "ipcsem.h"
00043
00044 #include <pwd.h>
00045 #include <sys/timeb.h>
00046 #include <sys/ipc.h>
00047 #include <sys/shm.h>
00048 #include <sys/sem.h>
00049
00050
00051
00052
00053
00054
00055 int
00056 getipckey()
00057 {
00058 const char a = 'a';
00059 int ascii_a = (int)a;
00060 char *curdir = NULL;
00061 char curdira[PATH_MAX];
00062 size_t size = sizeof(curdira);
00063 key_t ipc_key;
00064 struct timeb time_info;
00065
00066 if (NULL == (curdir = getcwd(curdira, size))) {
00067 tst_brkm(TBROK, cleanup, "Can't get current directory "
00068 "in getipckey()");
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 (void)ftime(&time_info);
00084 srandom((unsigned int)time_info.millitm);
00085
00086 if ((ipc_key = ftok(curdir, ascii_a + random()%26)) == -1) {
00087 tst_brkm(TBROK, cleanup, "Can't get msgkey from ftok()");
00088 }
00089
00090 return(ipc_key);
00091 }
00092
00093 #if 0
00094
00095
00096
00097 void
00098 rm_queue(int queue_id)
00099 {
00100 if (queue_id == -1) {
00101 return;
00102 }
00103
00104 if (msgctl(queue_id, IPC_RMID, NULL) == -1) {
00105 tst_resm(TINFO, "WARNING: message queue deletion failed.");
00106 tst_resm(TINFO, "This could lead to IPC resource problems.");
00107 tst_resm(TINFO, "id = %d", queue_id);
00108 }
00109 }
00110 #endif
00111
00112 #if 0
00113
00114
00115
00116 void
00117 init_buf(MSGBUF *m_buf, int type, int size)
00118 {
00119 int i;
00120 int ascii_a = (int)'a';
00121
00122
00123 for (i=0; i<size; i++) {
00124 m_buf->mtext[i] = ascii_a + (i % 26);
00125 }
00126
00127
00128 m_buf->mtext[i] = (char)NULL;
00129
00130
00131 if (type < 1) {
00132 m_buf->mtype = 1;
00133 } else {
00134 m_buf->mtype = type;
00135 }
00136 }
00137 #endif
00138
00139
00140
00141
00142 void
00143 rm_sema(int sem_id)
00144 {
00145 union semun arr;
00146
00147 if (sem_id == -1) {
00148 return;
00149 }
00150
00151 if (semctl(sem_id, 0, IPC_RMID, arr) == -1) {
00152 tst_resm(TINFO, "WARNING: semaphore deletion failed.");
00153 tst_resm(TINFO, "This could lead to IPC resource problems.");
00154 tst_resm(TINFO, "id = %d", sem_id);
00155 }
00156 }
00157
00158
00159
00160
00161 void
00162 check_root(void)
00163 {
00164 if (geteuid() != 0) {
00165 tst_brkm(TBROK, cleanup, "test must be run as root");
00166 }
00167 }
00168
00169
00170
00171
00172 int
00173 getuserid(char *user)
00174 {
00175 struct passwd *ent;
00176
00177
00178 if ((ent = (struct passwd *)malloc(sizeof(struct passwd))) == NULL) {
00179 tst_brkm(TBROK, cleanup, "couldn't allocate space for passwd"
00180 " structure");
00181 }
00182
00183
00184 if ((ent = getpwnam(user)) == NULL) {
00185 tst_brkm(TBROK, cleanup, "Couldn't get password entry for %s",
00186 user);
00187 }
00188
00189 return(ent->pw_uid);
00190 }
00191
00192
00193
00194
00195 void
00196 rm_shm(int shm_id)
00197 {
00198 if (shm_id == -1) {
00199 return;
00200 }
00201
00202
00203
00204
00205
00206 if (shmctl(shm_id, IPC_RMID, NULL) == -1) {
00207 tst_resm(TINFO, "WARNING: shared memory deletion failed.");
00208 tst_resm(TINFO, "This could lead to IPC resource problems.");
00209 tst_resm(TINFO, "id = %d", shm_id);
00210 }
00211 }