chiark / gitweb /
Fix stuck volume key presses for Toshiba Satellite U300 & U305models
[elogind.git] / extras / scsi_id / scsi_serial.c
index 0c9d9c3095e9723627c0f38740771329d6fcf976..dd5e1fdbf8f1cee7c6df2d9604f44c7d2b449c27 100644 (file)
@@ -1,17 +1,20 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+/*
+ * Copyright (C) IBM Corp. 2003
  *
- * scsi_serial.c
+ * Author: Patrick Mansfield<patmans@us.ibm.com>
  *
- * Code related to requesting and getting an id from a scsi device
+ * 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, either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Copyright (C) IBM Corp. 2003
+ * 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.
  *
- * Author:
- *     Patrick Mansfield<patmans@us.ibm.com>
- *
- *     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.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <sys/types.h>
@@ -863,21 +866,21 @@ int scsi_get_serial(struct udev *udev,
 {
        unsigned char page0[SCSI_INQ_BUFF_LEN];
        int fd = -1;
-       int cnt = 10;
+       int cnt;
        int ind;
        int retval;
 
        memset(dev_scsi->serial, 0, len);
        dbg(udev, "opening %s\n", devname);
-       while (--cnt) {
-               const struct timespec duration = { 0, 500 * 1000 * 1000 };
+       srand((unsigned int)getpid());
+       for (cnt = 20; cnt > 0; cnt--) {
+               struct timespec duration;
 
                fd = open(devname, O_RDONLY | O_NONBLOCK);
-               if (fd >= 0)
-                       break;
-               info(udev, "%s: cannot open %s: %s\n", dev_scsi->kernel, devname, strerror(errno));
-               if (errno != EBUSY)
+               if (fd >= 0 || errno != EBUSY)
                        break;
+               duration.tv_sec = 0;
+               duration.tv_nsec = (200 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
                nanosleep(&duration, NULL);
        }
        if (fd < 0)