aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bus.c11
-rw-r--r--src/nukectl.c19
2 files changed, 12 insertions, 18 deletions
diff --git a/src/bus.c b/src/bus.c
index 2c3f614..e28bda1 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -80,8 +80,8 @@ int scanbus_sysfs(nndevice_t** device)
}
else
{
- fgets(device[i]->model, sizeof(device[i]->model), fp);
- device[i]->model[strlen(device[i]->model) - 1] = 0;
+ if(fgets(device[i]->model, sizeof(device[i]->model), fp) != NULL)
+ device[i]->model[strlen(device[i]->model) - 1] = 0;
fclose(fp);
}
@@ -95,10 +95,11 @@ int scanbus_sysfs(nndevice_t** device)
}
else
{
- fgets(device[i]->vendor, sizeof(device[i]->model), fp);
- /* Why does sysfs not terminate the string after the last character? Kernel 2.6 bug?
+ /* Why does sysfs not terminate the string after the last character? Kernel 2.6 bug?
Here we are checking for the space character and terminating it manually. */
- device[i]->vendor[strind(device[i]->vendor, ' ')] = 0;
+ if((fgets(device[i]->vendor, sizeof(device[i]->model), fp)) != NULL)
+ device[i]->vendor[strind(device[i]->vendor, ' ')] = 0;
+
fclose(fp);
}
diff --git a/src/nukectl.c b/src/nukectl.c
index 82d9e94..2db3d06 100644
--- a/src/nukectl.c
+++ b/src/nukectl.c
@@ -28,6 +28,7 @@
#include "netnuke.h"
FILE* randfp;
+int writing = 0;
unsigned int randseed;
unsigned long long total_written_bytes = 0;
extern unsigned int blksz_override;
@@ -67,10 +68,7 @@ void* wipe(void* device)
}
if(blksz_override > 0)
{
- pthread_mutex_lock(&lock_global);
d->blksz = blksz_override;
- //d->blks = (d->blks / d->blksz);
- pthread_mutex_unlock(&lock_global);
}
int fd = open(d->path, O_WRONLY | O_SYNC);
@@ -80,27 +78,21 @@ void* wipe(void* device)
return (int*)1;
}
COM(self, "%s, block size %d, blocks %llu, total bytes %llu\n", d->path, d->blksz, d->blks, d->sz);
-
srand(nngetseed());
+
while(bytes_written <= d->sz)
{
- if((pthread_mutex_trylock(&lock_global)))
+ if(!writing)
{
- //COM(self, "tid %X %X got lock_global\n", pthread_self());
if(verbose_flag)
{
percent = (long double)((bytes_written / (long double)d->sz) * 100);
printf("%s: %llu of %llu (%0.2Lf%%)\n", d->path, bytes_written, d->sz, percent);
}
-
bytes_written += nnwrite(fd, d->blksz);
- pthread_mutex_unlock(&lock_global);
- }
- else
- {
- //COM(self, "tid %X %X did not get lock_global\n", pthread_self());
}
}
+
COM(self, "%s complete\n", d->path);
pthread_exit(NULL);
@@ -124,6 +116,7 @@ int nnwrite(int fd, int bsize)
unsigned int bytes_written = 0;
char* buffer = randstr(bsize);
pthread_mutex_lock(&lock_write);
+ writing = 1;
if(safety_flag)
{
/* simulation */
@@ -135,7 +128,7 @@ int nnwrite(int fd, int bsize)
//bytes_written = write(fd, buffer, bsize);
bytes_written += bsize;
}
-
+ writing = 0;
//total_written_bytes += bytes_written;
pthread_mutex_unlock(&lock_write);