2011-03-10 16:50:40 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2011-03-11 11:50:52 +01:00
|
|
|
#include <ioall.h>
|
2011-03-10 16:50:40 +01:00
|
|
|
#include "dvm2.h"
|
|
|
|
|
|
|
|
char *get_filename()
|
|
|
|
{
|
|
|
|
char buf[DVM_FILENAME_SIZE];
|
|
|
|
static char retname[sizeof(buf) + sizeof("/tmp/")];
|
|
|
|
if (!read_all(0, buf, sizeof(buf)))
|
|
|
|
exit(1);
|
|
|
|
if (index(buf, '/')) {
|
|
|
|
fprintf(stderr, "filename contains /");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
snprintf(retname, sizeof(retname), "/tmp/%s", buf);
|
|
|
|
return retname;
|
|
|
|
}
|
|
|
|
|
|
|
|
void copy_file(char *filename)
|
|
|
|
{
|
|
|
|
int fd = open(filename, O_WRONLY | O_CREAT, 0600);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("open file");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-03-11 11:54:39 +01:00
|
|
|
if (!copy_fd_all(fd, 0))
|
|
|
|
exit(1);
|
2011-03-10 16:50:40 +01:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void send_file_back(char * filename)
|
|
|
|
{
|
|
|
|
int fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("open file");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-03-11 11:54:39 +01:00
|
|
|
if (!copy_fd_all(1, fd))
|
|
|
|
exit(1);
|
2011-03-10 16:50:40 +01:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
char cmdbuf[512];
|
|
|
|
struct stat stat_pre, stat_post;
|
|
|
|
char *filename = get_filename();
|
|
|
|
|
|
|
|
copy_file(filename);
|
|
|
|
if (stat(filename, &stat_pre)) {
|
|
|
|
perror("stat pre");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
snprintf(cmdbuf, sizeof(cmdbuf),
|
2011-03-24 14:33:43 +01:00
|
|
|
"HOME=/home/user DISPLAY=:0 /usr/bin/mimeopen -n -M '%s' > /tmp/kde-open.log 2>&1 </dev/null",
|
2011-03-10 16:50:40 +01:00
|
|
|
filename);
|
|
|
|
if (system(cmdbuf))
|
2011-03-31 13:26:41 +02:00
|
|
|
#ifdef USE_KDIALOG
|
2011-03-10 16:50:40 +01:00
|
|
|
system
|
2011-03-24 14:33:43 +01:00
|
|
|
("HOME=/home/user DISPLAY=:0 /usr/bin/kdialog --sorry 'Unable to handle mimetype of the requested file!' > /tmp/kdialog.log 2>&1 </dev/null");
|
2011-03-31 13:26:41 +02:00
|
|
|
#else
|
|
|
|
system
|
|
|
|
("HOME=/home/user DISPLAY=:0 /usr/bin/zenity --error --text 'Unable to handle mimetype of the requested file!' > /tmp/kdialog.log 2>&1 </dev/null");
|
|
|
|
#endif
|
|
|
|
|
2011-03-10 16:50:40 +01:00
|
|
|
if (stat(filename, &stat_post)) {
|
|
|
|
perror("stat post");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (stat_pre.st_mtime != stat_post.st_mtime)
|
|
|
|
send_file_back(filename);
|
|
|
|
return 0;
|
|
|
|
}
|