Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Porting linux pthread app 2 FreeBSD-4.2

  • 17-09-2001 11:21pm
    #1
    Closed Accounts Posts: 5,564 ✭✭✭


    Hmmmmm what is the story with this?
    Seems as if simple threading against -lc_r works ok in FreeBSD-4.2 but in certain situations there is some weirdness with __pthread_connect? What the fsck? How come I could compile something simple like code in this post against -lc_r and not get strange references to __pthread_connect? Has anyone come across this problem or know the fix?


    /*Please disregard php tag ok?*/
    #include <signal.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <netinet/in.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <unistd.h>
    #include <pthread.h>

    typedef struct node{
    int scaned;
    struct node*next;
    }node_t;
    /*if we keep scanned ports in a linked list then maybe we can avoid constraints of arrays on number of ports to
    that we can scan or sumthin ?*/

    int makesock(int scanthis);
    void ifjoin(int successport);
    int makenode(int port);
    int scannode(int port);
    void delnode(void);
    void ctrl_c(int signal);

    pthread_t threads;
    node_t*head;
    char*ipaddress;
    void*retval;

    int main(int argc, char*argv[])
    {
    int scanthis;
    int highport,lowport,ipaddr,ctrl,x,e,f;
    int done=0;
    int true=1;
    if(argc<3)
    {printf("\nUsage skim [ipaddress] [lowport] [highport] [timeout]\n");
    printf("If you want to omit timeout for default 5 seconds umkay?\n\n\n");
    return -1;};

    ipaddress=argv[1];
    lowport=atoi(argv[2]);
    highport=atoi(argv[3]);
    if(argv[4]){
    f=atoi(argv[4]);
    if(f<=0)
    {f=5;};
    }
    else{f=5;};/*if user wants to specify a timeout see if we can allow else use default of 2 or sumthin?*/

    ctrl=highport-lowport;
    x=0;
    (void) signal(SIGINT, ctrl_c);
    while(true){
    do
    {scanthis=random()%highport;
    if(scanthis>=lowport)
    {
    if((scannode(scanthis)==0))
    {
    done=0;
    for(e=1; e<3;e++)
    {if(done==0)
    {pthread_create(&threads, NULL,(void*)makesock,(void*)scanthis);
    sleep(f);
    done=1;}
    else{pthread_cancel(threads);/*commenting this bad programming style? faster though?*/
    break;};/*if thread joins we should get a connect message right so otherwise we must
    terminate the thread correct?*/
    x++;};
    };/*if scannode*/
    }; /*if scanthis*/
    }while(x<ctrl); /*for x*/
    if(x=ctrl)
    break;};/*if true*/
    delnode();
    printf("Goodbye\n");
    return 0;
    };

    int makesock(int scanthis)
    { struct sockaddr_in address;
    int sckfd;
    int adrlen,x;
    sckfd=socket(AF_INET, SOCK_STREAM, 0);
    address.sin_family=AF_INET;
    address.sin_addr.s_addr=inet_addr(ipaddress);
    address.sin_port=htons(scanthis);
    adrlen=sizeof(address);
    makenode(scanthis);
    x=connect(sckfd,(struct sockaddr*)&address, adrlen);
    if(x==0){
    ifjoin(scanthis);
    };
    return 0;
    };

    void ifjoin(successport)
    {

    pthread_join(threads,NULL);
    printf("port %d open\n",successport);
    return;
    };

    int makenode(int port)
    {
    static node_t*make;
    static nummade;
    make=(node_t*)malloc(sizeof(node_t));
    make->scaned=port;
    make->next=head;
    head=make;
    make++;
    return 0;
    };

    int scannode(int port)
    {
    node_t*scan;
    scan=head;
    while(scan!=NULL)
    {if(scan->scaned==port)
    return -1;
    scan=scan->next;};
    return 0;
    };

    void delnode(void)
    {
    node_t*deln;
    while(head!=NULL)
    {deln=head;
    head=head->next;
    free(deln);
    };
    return;
    };

    void ctrl_c(int signal)
    {
    printf("Received interrupt signal\n");
    printf("Please wait while I release allocated memory umkay?\n");
    delnode();
    exit(0);
    return;
    };


Comments

  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    What kind of error message are you getting? Give us some output please.

    Al.


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Specifically I think
    undefined reference to __pthread_connect (which is why I find above confusing) if you see the use of connect?
    &
    undefined reference to __pthread_read , undefined reference to __pthread_write , but it seems as if I could use send recv in place of where I have used these, however the errors with connect or the threaded connect (__pthread_connect which is presumably available in -lpthread, but not in -lc_r)I doubt I would have any luck finding a replacement for connect do you? Also I did seem so have pthread in /usr/local/lib/pthread_someversion - which I tried putting into /usr/lib with relevant symlinks to make pthread.so yeah? And it would seem to compile fine but just not thread yeah? Instead of thread it seems as best it may just execute the function without creating a seperate thread of execution, but what do you expect from a hack like that?
    HELP.

    Seems as if FreeBSDers are slightly aware of problems with 4.2, but I would like to know if there is some reasonable workaround?



    http://gtklex.sourceforge.net/gtklex_1_0.tar.bz2


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan




  • Moderators, Social & Fun Moderators Posts: 10,501 Mod ✭✭✭✭ecksor


    I assume you did a man pthread on FreeBSD and saw this bit?

    A FreeBSD specific option has been added to gcc to make linking threaded
    processes simple. gcc -pthread links a threaded process against libc_r
    instead of libc.

    Doesn't look like it does anything different to -lc_r, but you never know ...


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    I'm assuming that (hopefully) the configure script will figure out if pthreads are supported and then link against the right lib as appropiate, here if you want to dload the sources etc
    http://gtklex.sourceforge.net

    Oh btw if anyone is interested in getting involved in some os project and has some contrib to make then do let me know ok?
    cout@eircom.net


  • Advertisement
  • Closed Accounts Posts: 296 ✭✭moist


    Hopefully Gtklex will enable the end user to download files via HTTP or FTP suspend, and resume an indefinate number of times.

    Erm whats wrong with 'wget -c' ?

    Anyhow, There were thread problems with 4.2 (sadly due to some rushed code changes >:| ) I don't know
    of any 'fix' apart from upgrading.
    You could search the mailing list archives, or perhaps ask on one of the lists.

    I tried the code on my 4.4 machine but it started complaining about autoconf and gnome.
    I really don't want to go there at this time in the morning :)


Advertisement