read() and label funkiness



I have a small program that reads in a file and displays the text content in 
a gtk label.  the function that opens the file, reads the file, and sets the 
text of the label is on a gtk timeout, set to refresh every five seconds.  
the arrangement seems to work fine at first, and the program seems to be 
functioning correctly, but when i leave it running for a long period of 
time, i.e., 24+ hours, the label starts to become gibberish.  A normal label 
should read "PPP connection is UP," the bad one reads something along the 
lines of "PPP connection 54.@78%@."

so what's the problem?  i have included the relevant source below.

gint timeout_callback(gpointer data)
{
    int pppd_fd; //the fd for the file
    char *label_text_ptr;
    label_text_ptr = malloc(1000);

    pppd_fd = open ("/etc/ppp/pppd.status", O_RDONLY); //get the fd
    read(pppd_fd, label_text_ptr, 25);//read 25 bytes
    gtk_label_set_text(GTK_LABEL( (GtkWidget*)data ), label_text_ptr);
    free(label_text_ptr);
}
int main( int   argc,
          char *argv[] )
{
    GtkWidget *label;

    gpointer data_ptr;
/* ... */
    //the label
    label = gtk_label_new("checking connection...");
    gtk_container_add(GTK_CONTAINER(frame), label);

/* ... */
    data_ptr = (gpointer) label;

    timeout_callback(data_ptr);
    gtk_timeout_add(60000, timeout_callback, data_ptr);

    gtk_main ();

    return 0;
}

thanks for any insight into this bizarre problem
-bennyk
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]