1 #include "mainwindow.h"
4 #include <unistd.h> // for fork()
5 #include <sys/types.h> // for pid_t
6 #include <sys/wait.h> // for waitpid()
7 #include "pirexception.h"
12 #include <QtGui/QApplication>
17 // First, fork off a child process:
22 // The fork failed! Tell our user about the error:
24 ss << "Failed to fork a child process.\n";
25 ss << "Error returned was: " << strerror(errno) << "\n";
26 PIRException e(ss.str());
32 // We're inside the child process, so exec a modprobe:
33 execl("/sbin/modprobe", "/sbin/modprobe", "lirc_rx51", NULL);
34 // The execl call should overwrite the child process. So, if we still
35 // exist at this point, an error has occurred:
37 ss << "Failed to successfully call execl().\n";
38 ss << "Error returned was: " << strerror(errno) << "\n";
39 PIRException e(ss.str());
44 // If we reach this point, we are inside the parent process. So, we'll wait
45 // for the child process to complete:
47 if (waitpid(pid, stat_loc, 0) == -1)
49 // The call to modprobe failed.
51 ss << "Call to modprobe failed.\n";
52 ss << "Error returned was: " << strerror(errno) << "\n";
53 PIRException e(ss.str());
60 if (WIFEXITED(*stat_loc) == 0)
62 // modprobe encountered an error of some sort.
64 ss << "'modprobe' was unable to load the lirc_rx51 module.\n";
65 // Need better details about the error here!
66 PIRException e(ss.str());
72 // By this point, we should have successfully ensured the module is loaded.
77 int main(int argc, char *argv[])
79 QApplication app(argc, argv);
81 MainWindow mainWindow;
82 mainWindow.setOrientation(MainWindow::ScreenOrientationLockLandscape);
83 mainWindow.showExpanded();
86 // Make sure lirc_rx51 module is loaded:
87 if (loadRX51Module() != 0)
89 // Couldn't load module, quit: