Changing ownership of sym links

As part of the S/W upgrade process for our product we create sym links to certain directories and files.

However the upgrade process runs as a different user so all the files created during the upgrade have their ownership set to the wrong user.

A simple issuing of chown -R * works for everything but sym links. In the case of sym links the ownership is not changed because what happens is the chown command follows the sym link and changes the ownership of the file it points to.

So I have a question. Is it possible to change ownership and group for a sym link? From the doc’s it doesn’t appear that it’s possible. A web search revealed that under Linux there is a command called lchown to handle this case. But I don’t see the equivalent under QNX.

TIA,

Tim

There is lchown() in libc, you need something like this.

$ cat lchown.c
#include <stdio.h>

int main(int argc, char **argv)
{
        if (argc < 4) {
                printf("lchown uid gid file\n");
                return 0;
        }
        return lchown(argv[3], atoi(argv[1]), atoi(argv[2]));
}

xtang,

Cool. Thanks. I compiled and added lchown to my bin directory and it works great.

I wonder why QNX didn’t include this as a binary since it would be so trivial to implement?

Tim

Probably because there is very little need to change the ownership of a symbolic link. They are usually created with ownership of root, all everyone has permission. Any actions you take will then depend on the target of the link (which is the behaviour you would expect).

Rick…