switch to room list switch to menu My folders
Go to page: [1] 2 3 4 5 ... Last
↑↑↑ Old messages ↑↑↑            ↓↓↓ New messages ↓↓↓
[#] Fri Dec 21 2012 07:03:42 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I'm in an increasingly peculiar position at work now, and I wonder if I could get a little help in one specific area.

My boss insisted that we create software that runs in the Windows environment.
He came to this decision long ago because he's familiar with the operating system, and could therefore do maintenance on any machines running with that operating system. He also has a bias against free software, because he has been burned several times by people who didn't really understand the full costs of working with such software, and failed to anticipate certain concerns well.

Today, he has had a change of heart. I suspect his exposure to the Android OS, layered on top of Linux as it is, caused him to rethink his position.
He has asked me a few times how difficult it would be to migrate everything over to Linux, etc.

I'd love to do this, because:

1. I've always wanted to program for posix operating systems.
2. I want to expand my skillset out of Windows.
3. Linux seems like it will be more stable than the many-and-varied ways in which Microsoft fucks with the Windows OS to make it harder to do relatively simple things (like editing a text file and saving it without any problems... yes, Windows has become so bad that you can't always do this without having to go through your asshole).
4. We might be able to save money using Linux instead of paying for Windows licenses.
5. Less of a hassle during installation. Maybe.

So why am I posting this in Programming instead of Linux? Because I need to start this migration with simple things before I get to the larger things, and the simple thing I want to focus on right now is the Windows service integration vs. posix daemons.

(continued in the next post)

[#] Fri Dec 21 2012 07:17:01 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

In Windows, our long-running services integrate with a Service Control Manager (SCM). The SCM provides a framework for controlling services, by letting you stop, start, pause, and perhaps send specialized signals to the service through its framework. You have to make specialized calls to the operating system to install or remove the service, and those calls can be made in such a way as to have the service start automatically, or manually.

I know enough about posix to know that you can't call a function to install the daemon, that such things are handled by scripts that invoke your service and that other scripts control whether or not your daemon is started automatically or manually, so I am not concerned about that exactly.

I'm more interested in what it takes to set up a daemon. I assume that it has to listen to signals (like KILL and HUP) and react appropriately to those signals.

Basically, I want to take the core code I use now for creating a Windows service, and add to it, to make it also create a posix daemon, so I don't have to write specialized code for Windows vs. posix. That is, I want to derive a class in C++ from a 'process' class (perhaps), who then calls functions like run(), on_stop(), on_pause() or the like depending on the signal received (in posix) or the SCM signal received (in Windows).

I already have code that helps me set up a Windows NT service easily by deriving a class and overriding its Run, OnStop, OnPause, etc. functions. I think I want something similar for posix, but is identical enough that a compiler #define would cause either the NT Service or Posix code to get compiled as appropriate.

I would be willing to make this code available to everyone, since I don't think something like this is a core company holding, but would be very useful to a lot of people.

And the majority of this code would exist as a series of headers. I don't like writing dynamic or static libraries, preferring header libraries for something like this. That would help to keep everything light, although you'll need to use certain macros to help create the 'main' function, etc.

[#] Fri Dec 21 2012 07:20:29 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

So, I suppose, I'm looking for advice. Some of you (IG in particular) have a lot of experience writing daemons for posix. I have a lot of experience writing NT services. I'd like to merge these two expertises into a single code set that can work for both OSes.

Later, I'll post the code I currently have for creating an NT service. This code is a lightly modified version of code I found on Dr Dobbs. The modifications were intended to make it easier to create an NT service (derive a class and call a macro).

[#] Fri Dec 21 2012 09:01:51 EST from dothebart @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

we do something like this:

#ifdef __WIN32__


WinMain (HINSTANCE ThisInstance, HINSTANCE hPrevInstance, char *lpCmdLine,
     int nCmdShow)

    return (0);

#else /* WIN32 Console Server */

WinMain (HINSTANCE ThisInstance, HINSTANCE hPrevInstance, char *lpCmdLine,
     int nCmdShow)
    return the_real_main(...);


#else /* UNIX */

main (int argc, char* argv[])
    return the_real_main (argc, argv);



I guess that doesn't exactly all those hooks for windows services...


heres a signal handler from citserver:

static RETSIGTYPE signal_cleanup(int signum) {
    syslog(LOG_DEBUG, "Caught signal %d; shutting down.", signum);
    exit_signal = signum;
    server_shutting_down = 1;


maybe winelib already has something to offer for you that fulfills much of your needs?

[#] Fri Dec 21 2012 11:44:25 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I have attached my ntservice.h file.

This is actually a refinement from what I normally use at my job, in that it's a single header... I usually have much of the functions in a separate .cpp file that I pull in as an include.

Hopefully, this gives you an idea of where I'm going, at least in C++.

ntservice.h (text/plain, 19573 bytes) [View| Download]
[#] Fri Dec 21 2012 12:52:21 EST from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Good luck... migrations can take significant time.

[#] Fri Dec 21 2012 22:56:25 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Yeah... the approach I want to take involves slowly converting the code to work on both operating systems instead of being exclusive to Windows, then have some additional stuff built specific to Linux that addresses some of the OS-centric stuff that we want to 'simplify' for users (e.g. setting up networking, serial connections for certain applications, etc).  This effort alone could take a good while, especially when I still have to write code for new products and features, too.

It could take me a very long time to accomplish this, especially since I rely rather heavily on DirectShow for streaming audio/video.  I'll have to learn how to approach things the same way that VLC does for that stuff... and hope that the codecs in Linux are at least as good as the ones we use now.

I also have to navigate the whole licensing thing, since we don't want to release too much of our code to the public, out of concern for competition.  Personally, I don't think this ought to be as much of a concern (since this kind of technology doesn't really make a tremendous amount of money), but habits die hard sometimes.

In the end, I hope it's possible.  But if I wind up generating some interesting code that other folks could use in the process, then we're all the better for me trying.

[#] Tue Dec 25 2012 16:54:18 EST from IGnatius T Foobar @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

The POSIX service startup/shutdown stuff is significantly less complex than it is on Windows. The downside is that it uses shell scripts, so there's more futzing around during the installation process.

Even among unix-like systems there'd be some use for an abstraction layer, to smooth over the difference between classic SysV init vs. Upstart vs. whatever Apple uses.

It sounds like the logical place for this to go would be a system where you provide a program that "does something" and then you let the system handle the dirty work of starting it up and shutting it down.

Wasn't your former employer owned by InstallShield? If so there could be some legal hurdles...

[#] Wed Dec 26 2012 11:26:25 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I doubt there would be any legal problems... the code I used is based strongly off something written in an article in Dr. Dobbs.  I've only very lightly tweaked it to make it easier to use.

Even so, the code was written for use with the captioning company, not WinINSTALL (never did work with Installshield).  And even when I worked on WinINSTALL, we left VERITAS before they merged with Symantec, so I never wrote code that made it into Symantec's corporation.  I just wound up with some Symatec stock due to the stock I had in VERITAS.

Okay, well, I suppose I should write a first pass at a class for posix-based systems, and perhaps find out what doesn't work if people complain about stuff.  I should also read about how Boost figures out various environments, so I can make it so you include one header regardless of what operating system you're using.

Aaand, I guess, I should see if I have a linux VM somewhere as well, for testing.

[#] Sat Jan 05 2013 13:51:05 EST from zooer @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Having a problem I can't figure out. That thing called Google was of no
help. I created a script but I can't get it to execute without typing
".sh" after the file name.

The files are in the bin directory in my home directory.
The permissions for that director allows executable programs.
I have another script in that directory that runs using the
filename without the ".sh" at the end.
"#!/bin/bash" is at the begining of both files.
"#!/bin/sh" caused some error in the "sendpic" script and didn't
solve the problem of allowing helen to execute without the ".sh"
Here is the directory and screen output.

-rwxr-xr-x 1 zooer zooer 97 Jan 5 09:05
-rwxr-xr-x 1 zooer zooer 6.7K Jan 5 09:09
drwxr-xr-x 2 zooer zooer 4.0K Jan 5 09:12 .
zooer@zooer-Linux12:~/bin$ helen
helen: command not found
zooer@zooer-Linux12:~/bin$ (executes as it should)

zooer@zooer-Linux12:~/bin$ sendpic (executes as it should)
/home/zooer/Pictures/webcam/front-cam.jpg: 67.86 kB 6.67 kB/s

I am not sure what I have to do to get helen to execute without the .sh
at the end. I am sure it is something simple. Can you help? I will
buy someone something from the TacoBell dollar menu.

[#] Sat Jan 05 2013 15:56:24 EST from dothebart @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

remember, you're in unix here. filenames are what they are.

if you insist to call it, you have to call it as

if you want to call it blabbla, either name it that way or symlink it.

everything in your PATH environment variable is used to search for filenames.

[#] Sat Jan 05 2013 17:13:38 EST from zooer @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

So why does one "blabla" work without the ".sh" but "yackity" does not work without the ".sh"?

[#] Sat Jan 05 2013 18:45:24 EST from the_mgt @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


Sat Jan 05 2013 23:13:38 CET from zooer @ Uncensored
So why does one "blabla" work without the ".sh" but "yackity" does not work without the ".sh"?
you probably have a false positive. yackity also lives in /usr/bin or /usr/local/bin or anywhere in $PATH is my suggestion. what does "which blabla" say?


[#] Sat Jan 05 2013 19:26:47 EST from zooer @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Both files are in the same directory, my bin directory, which is in my path statement.

This is a new install so it shouldn't be in /usr/bin.

[#] Sat Jan 05 2013 21:29:14 EST from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

the important question is not "why doesn't helen execute" but "why does sendpic execute".

helen should not execute
sendpic should not execute.

maybe you created a bash alias that you forgot about?

[#] Sun Jan 06 2013 00:23:42 EST from ax25 @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Where in the path statment, before or after the home bin location?

echo $PATH

Location matters.  First found is first run.

Remember, if you want to run a command under Unix (without descrepancy), you might want to say run from the current location i.e.:


[#] Sun Jan 06 2013 09:46:16 EST from zooer @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

maybe you created a bash alias that you forgot about?

BINGO! Thank you.

This system is a new install which I did around Christmas, I have a text file list of changes and
adjustments I want to make on new installs, that alias is not in that list. I must have cut and
pasted it from one of the other distros in my multi-boot system.

I knew did something to call the file (Two years ago) but couldn't remember what it was. Something so
simple it was silly. It is all coming back.

Thank you.

[#] Mon Jan 14 2013 23:29:04 EST from IGnatius T Foobar @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

The easier way would be to simply omit the '.sh' from the filename in the first place. Make it executable, put it in your search path, and include '#!/bin/bash'
on the first line for good measure.

[#] Wed Jan 16 2013 11:25:29 EST from zooer @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Yes I thought about eliminating the ".sh" but I like file extensions.

[#] Fri Feb 01 2013 09:58:42 EST from dothebart @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

using the c-pre processor to generate html:


Go to page: [1] 2 3 4 5 ... Last