1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/*
* Copyright (c) 2001-2002 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 1998-2001 University of Notre Dame.
* All rights reserved.
* Copyright (c) 1994-1998 The Ohio State University.
* All rights reserved.
*
* This file is part of the LAM/MPI software package. For license
* information, see the LICENSE file in the top level directory of the
* LAM/MPI source distribution.
*
* $HEADER$
* Ohio Trollius
* Copyright 1997 The Ohio State University
* GDB/RBD
*
* $Id: kattach.c,v 1.4 2002/10/09 20:57:47 brbarret Exp $
*
* Function: - attaches calling process to the kernel
* Accepts: - process scheduling priority
* Returns: - 0 or ERROR
*/
#include <lam_config.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <kio.h>
#include <kreq.h>
#include <typical.h>
#include <etc_misc.h>
/*
* external variables
*/
extern struct kio_t _kio; /* Kernel I/O block */
/*
* external functions
*/
extern int _cio_kreq(); /* make kernel request */
extern void _ksig_follow(); /* follow signals */
int
kattach(priority)
int priority;
{
struct kreq req; /* kernel request */
struct kreply reply; /* kernel reply */
sigset_t newset; /* new signal set */
sigset_t oldset; /* old signal set */
LAM_ZERO_ME(req);
LAM_ZERO_ME(reply);
req.kq_req = KQATTACH;
req.kq_index = _kio.ki_index;
req.kq_pid = lam_getpid();
req.kq_priority = priority;
/*
* Send the request to the kernel and receive a reply.
*/
sigemptyset(&newset);
sigaddset(&newset, LAM_SIGUSR);
sigprocmask(SIG_BLOCK, &newset, &oldset);
if (_cio_kreq(&req, &reply)) {
sigprocmask(SIG_SETMASK, &oldset, (sigset_t *) 0);
return(LAMERROR);
}
if (reply.kr_reply) {
sigprocmask(SIG_SETMASK, &oldset, (sigset_t *) 0);
errno = reply.kr_reply;
return(LAMERROR);
}
_kio.ki_index = reply.kr_index;
_kio.ki_rtf |= RTF_KERNEL;
_kio.ki_pid = lam_getpid();
_kio.ki_priority = priority;
sigprocmask(SIG_SETMASK, &oldset, (sigset_t *) 0);
if (reply.kr_signal) {
_kio.ki_signal |= reply.kr_signal;
_ksig_follow();
}
return(0);
}
|