Mercurial > illumos > illumos-gate
changeset 3180:6284d3cace2d
6469348 lofiadm shouldn't depend on syseventd
author | vikram |
---|---|
date | Mon, 27 Nov 2006 13:59:19 -0800 |
parents | 80729b9ca1d6 |
children | 65ef60e5a248 |
files | usr/src/cmd/lofiadm/Makefile usr/src/cmd/lofiadm/main.c |
diffstat | 2 files changed, 32 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/lofiadm/Makefile Mon Nov 27 13:19:44 2006 -0800 +++ b/usr/src/cmd/lofiadm/Makefile Mon Nov 27 13:59:19 2006 -0800 @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -21,8 +20,8 @@ # # # -# Copyright (c) 1999 by Sun Microsystems, Inc. -# All rights reserved. +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. # #pragma ident "%Z%%M% %I% %E% SMI" # @@ -34,6 +33,8 @@ include ../Makefile.cmd +LDLIBS += -ldevinfo + .KEEP_STATE: all: $(PROG)
--- a/usr/src/cmd/lofiadm/main.c Mon Nov 27 13:19:44 2006 -0800 +++ b/usr/src/cmd/lofiadm/main.c Mon Nov 27 13:59:19 2006 -0800 @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,8 +19,8 @@ * CDDL HEADER END */ /* - * Copyright (c) 1999-2000 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. * * lofiadm - administer lofi(7d). Very simple, add and remove file<->device * associations, and display status. All the ioctls are private between @@ -43,6 +42,7 @@ #include <stdlib.h> #include <unistd.h> #include <stropts.h> +#include <libdevinfo.h> #include "utils.h" static const char USAGE[] = @@ -135,11 +135,29 @@ int cursleep; char blkpath[MAXPATHLEN + 1]; char charpath[MAXPATHLEN + 1]; + di_devlink_handle_t hdl; + (void) snprintf(blkpath, sizeof (blkpath), "/dev/%s/%d", LOFI_BLOCK_NAME, minor); (void) snprintf(charpath, sizeof (charpath), "/dev/%s/%d", LOFI_CHAR_NAME, minor); + + /* Check if links already present */ + if (stat64(blkpath, &buf) == 0 && stat64(charpath, &buf) == 0) + return; + + /* First use di_devlink_init() */ + if (hdl = di_devlink_init("lofi", DI_MAKE_LINK)) { + (void) di_devlink_fini(&hdl); + goto out; + } + + /* + * Under normal conditions, di_devlink_init(DI_MAKE_LINK) above will + * only fail if the caller is non-root. In that case, wait for + * link creation via sysevents. + */ cursleep = 0; while (cursleep < maxsleep) { if ((stat64(blkpath, &buf) == -1) || @@ -150,7 +168,10 @@ } return; } + /* one last try */ + +out: if (stat64(blkpath, &buf) == -1) { die(gettext("%s was not created"), blkpath); }