udevsettle.c revision 225cb03bd851adc6d269b13bdf2b1bfded2b96b9
/*
* Copyright (C) 2006 Kay Sievers <kay@vrfy.org>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
#include <syslog.h>
#include <getopt.h>
#include "udev.h"
#include "udevd.h"
#define DEFAULT_TIMEOUT 180
#define LOOP_PER_SECOND 20
{
unsigned long long seq_kernel;
unsigned long long seq_udev;
char seqnum[32];
int fd;
int timeout = DEFAULT_TIMEOUT;
int loop;
{}
};
int option;
int rc = 1;
int seconds;
logging_init("udevsettle");
sysfs_init();
while (1) {
if (option == -1)
break;
switch (option) {
case 't':
if (seconds > 0)
else
break;
case 'h':
printf("Usage: udevadm settle [--help] [--timeout=<seconds>]\n\n");
goto exit;
}
}
while (loop--) {
/* wait for events in queue to finish */
while (loop--) {
info("queue is empty");
break;
}
}
if (loop <= 0) {
info("timeout waiting for queue");
goto exit;
}
/* read current udev seqnum */
if (fd < 0)
goto exit;
if (len <= 0)
goto exit;
/* read current kernel seqnum */
if (fd < 0)
goto exit;
if (len <= 0)
goto exit;
/* make sure all kernel events have arrived in the queue */
if (seq_udev >= seq_kernel) {
info("queue is empty and no pending events left");
rc = 0;
goto exit;
}
info("queue is empty, but events still pending");
}
exit:
return rc;
}