/* * uevent_check.c - check for uevent socket * * based on uevent_listen.c * * Copyright (C) 2004 Kay Sievers * Copyright (C) 2004 Hannes Reinecke * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2 of the License. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { int sock; struct sockaddr_nl snl; int retval; if (getuid() != 0) { fprintf(stderr,"need to be root, exit\n"); exit(0); } memset(&snl, 0x00, sizeof(struct sockaddr_nl)); snl.nl_family = AF_NETLINK; snl.nl_pid = getpid(); snl.nl_groups = 0xffffffff; sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); if (sock == -1) { fprintf(stderr,"error getting socket, exit\n"); exit(1); } retval = bind(sock, (struct sockaddr *) &snl, sizeof(struct sockaddr_nl)); if (retval < 0) { fprintf("bind failed, exit\n"); exit(1); } fprintf(stderr,"uevent socket available"); exit(0); }